Benutzer-Werkzeuge

Webseiten-Werkzeuge


scriptstack

Unterschiede

Hier werden die Unterschiede zwischen zwei Versionen angezeigt.

Link zu dieser Vergleichsansicht

Beide Seiten der vorigen Revision Vorhergehende Überarbeitung
Nächste Überarbeitung
Vorhergehende Überarbeitung
scriptstack [2025/12/16 17:02]
jango
scriptstack [2025/12/30 17:42] (aktuell)
admin [Models]
Zeile 7: Zeile 7:
 Lexer.cs::GetTokens() -> State und Daten erfassen Lexer.cs::GetTokens() -> State und Daten erfassen
  
-Parser.cs::Literal() -> den Case hinzufügen und decimal zurückgeben +Parser.cs::Literal() -> den Case decimal hinzufügen 
-Parser.cs::Atom() -> den case hinzufügen der den token decimal als literal annimmt+Parser.cs::Atom() -> den case decimal hinzufügen 
  
 Interpreter.cd::Arithmetic() -> decimal auch berechnen Interpreter.cd::Arithmetic() -> decimal auch berechnen
 +
 +Routine::Validate() -> decimal hinzufügen
  
 =====Manager===== =====Manager=====
Zeile 222: Zeile 224:
  
 <code csharp>   <code csharp>  
-public class TrigonometryModule +using ScriptStack.Runtime; 
- HostModule +using System; 
-+ 
- // list of functions stored statically for one-off creation +namespace ScriptStack { 
- private static ReadOnlyCollection<hostfunctionprototype /> + 
-s_listHostFunctionPrototypes+    public class ExampleModel 
- // module constructor +     
- public TrigonometryModule() +        private static ReadOnlyCollection < Routine exportedRoutines
- + 
- // if list created, don't do anything else +        public Example() { 
- if (s_listHostFunctionPrototypes != null) return; + 
-  +            if (exportedRoutines != null) 
- // create list of function prototypes +                return; 
- List<hostfunctionprototype /> listHostFunctionPrototypes = + 
- new List<hostfunctionprototype />(); +            var r = new List<Routine>(); 
- HostFunctionPrototype hostFunctionPrototype = null; + 
- // add Sine prototype to list +            r.Add(new Routine(typeof (bool), "std.print", (Type) null, "Ausgabe auf der Konsole erzeugen.")); 
- hostFunctionPrototype =  +            r.Add(new Routine(typeof (int), "std.read", "Einen Tastenanschlag von der Konsole lesen.")); 
- new HostFunctionPrototype(typeof(float), "Sin", typeof(float)); +            r.Add(new Routine(typeof (string), "std.readLine", "Eine Zeile von der Konsole lesen.")); 
- listHostFunctionPrototypes.Add(hostFunctionPrototype); + 
- // add Cosine prototype to list +            exportedRoutines r.AsReadOnly(); 
- hostFunctionPrototype =  + 
- new HostFunctionPrototype(typeof(float), "Cos", typeof(float)); +        
- listHostFunctionPrototypes.Add(hostFunctionPrototype); + 
- // add Tangent prototype to list +        public ReadOnlyCollection < Routine Routines => exportedRoutines
- hostFunctionPrototype =  + 
- new HostFunctionPrototype(typeof(float), "Tan", typeof(float)); +        public object Invoke(string routine, List <object> parameters) { 
- listHostFunctionPrototypes.Add(hostFunctionPrototype); + 
- s_listHostFunctionPrototypes  +            if (routine == "std.print"{ 
- listHostFunctionPrototypes.AsReadOnly(); +                System.Console.Write(parameters[0]); 
- } +                return true; 
- // returns list of available functions +            } 
- public ReadOnlyCollection<hostfunctionprototype /HostFunctionPrototypes + 
- { +            if (routine == "std.read") 
- get { return s_listHostFunctionPrototypes} +                return (intSystem.Console.ReadKey().Key
- + 
- // implements functions +            if (routine == "std.readLine") 
- public object OnHostFunctionCall(String strFunctionName +                return System.Console.ReadLine(); 
- List<object> listParameters) + 
- +            return null; 
- if (strFunctionName == "Sin") +        } 
- // implement Sine +    }
- return (float)Math.Sin((float)listParameters[0]); +
- else if (strFunctionName == "Cos") +
- // implement Cosine +
- return (float)Math.Cos((float)listParameters[0]); +
- else if (strFunctionName == "Tan") +
- // implement Tangent +
- return (float)Math.Tan((float)listParameters[0]); +
- // unknown function (should not happen) +
- throw new ExecutionException( +
- "Unimplemented function '" + strFunctionName + "'."); +
- }+
 } }
 </code> </code>
Zeile 282: Zeile 273:
 <code csharp> <code csharp>
 // create module instance // create module instance
-TrigonometryModule trigonometryModule = new TrigonometryModule();+Model example = new Example();
 // register module // register module
-m_scriptManager.RegisterHostModule(trigonometryModule)+Manager.Register(example)
 </code> </code>
scriptstack.1765900959.txt.gz · Zuletzt geändert: 2025/12/16 17:02 von jango