Hier werden die Unterschiede zwischen zwei Versionen angezeigt.
| Beide Seiten der vorigen Revision Vorhergehende Überarbeitung Nächste Überarbeitung | Vorhergehende Überarbeitung | ||
|
scriptstack [2025/12/15 02:46] jango [Routines] |
scriptstack [2025/12/30 17:42] (aktuell) admin [Models] |
||
|---|---|---|---|
| Zeile 1: | Zeile 1: | ||
| + | =====Interna===== | ||
| + | |||
| + | ====Neuen Datentyp hinzufügen==== | ||
| + | |||
| + | Token.cs -> Neuen Tokentyp erstellen (Decimal) | ||
| + | Lexer.cs -> Neuen State hinzufügen (Decimal) | ||
| + | Lexer.cs:: | ||
| + | |||
| + | Parser.cs:: | ||
| + | Parser.cs:: | ||
| + | |||
| + | Interpreter.cd:: | ||
| + | |||
| + | Routine:: | ||
| + | |||
| =====Manager===== | =====Manager===== | ||
| Zeile 186: | Zeile 201: | ||
| <code csharp> | <code csharp> | ||
| // register global Sine function | // register global Sine function | ||
| - | HostFunctionPrototype hostFunctionPrototype | + | Routine routine |
| - | typeof(float), | + | manager.Register(routine, printHandler); |
| - | m_scriptManager.RegisterHostFunction(hostFunctionPrototype, trigHandler); | + | |
| // register global Cosine function | // register global Cosine function | ||
| - | HostFunctionPrototype hostFunctionPrototype | + | routine |
| - | | + | manager.Register(routine, readHandler); |
| - | m_scriptManager.RegisterHostFunction(hostFunctionPrototype, | + | |
| - | // register global Tangent function | + | |
| - | HostFunctionPrototype hostFunctionPrototype = new HostFunctionPrototype( | + | |
| - | typeof(float), | + | |
| - | m_scriptManager.RegisterHostFunction(hostFunctionPrototype, trigHandler); | + | |
| </ | </ | ||
| Zeile 214: | 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 { |
| - | | + | |
| - | s_listHostFunctionPrototypes; | + | |
| - | // module constructor | + | |
| - | | + | private static ReadOnlyCollection < Routine |
| - | { | + | |
| - | // if list created, don't do anything else | + | public |
| - | if (s_listHostFunctionPrototypes | + | |
| - | + | if (exportedRoutines | |
| - | // create list of function prototypes | + | |
| - | | + | |
| - | new List<hostfunctionprototype />(); | + | var r = new List<Routine>(); |
| - | HostFunctionPrototype hostFunctionPrototype = null; | + | |
| - | // add Sine prototype to list | + | |
| - | | + | r.Add(new |
| - | | + | r.Add(new |
| - | listHostFunctionPrototypes.Add(hostFunctionPrototype); | + | |
| - | // add Cosine prototype to list | + | |
| - | | + | |
| - | new HostFunctionPrototype(typeof(float), "Cos", | + | |
| - | listHostFunctionPrototypes.Add(hostFunctionPrototype); | + | |
| - | // add Tangent prototype to list | + | public ReadOnlyCollection < Routine |
| - | | + | |
| - | new HostFunctionPrototype(typeof(float), "Tan", | + | public object |
| - | listHostFunctionPrototypes.Add(hostFunctionPrototype); | + | |
| - | s_listHostFunctionPrototypes | + | |
| - | | + | |
| - | } | + | |
| - | // returns list of available functions | + | } |
| - | | + | |
| - | { | + | |
| - | get { return s_listHostFunctionPrototypes; } | + | return (int) System.Console.ReadKey().Key; |
| - | } | + | |
| - | // implements functions | + | |
| - | | + | return |
| - | List< | + | |
| - | { | + | |
| - | if (strFunctionName | + | } |
| - | // implement Sine | + | } |
| - | | + | |
| - | else if (strFunctionName | + | |
| - | // implement Cosine | + | |
| - | return (float)Math.Cos((float)listParameters[0]); | + | |
| - | else if (strFunctionName | + | |
| - | // implement Tangent | + | |
| - | return | + | |
| - | // unknown function (should not happen) | + | |
| - | throw new ExecutionException( | + | |
| - | " | + | |
| - | } | + | |
| } | } | ||
| </ | </ | ||
| Zeile 274: | Zeile 273: | ||
| <code csharp> | <code csharp> | ||
| // create module instance | // create module instance | ||
| - | TrigonometryModule trigonometryModule | + | Model example |
| // register module | // register module | ||
| - | m_scriptManager.RegisterHostModule(trigonometryModule) | + | Manager.Register(example) |
| </ | </ | ||