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/15 02:19]
jango [Routines]
scriptstack [2025/12/15 02:50] (aktuell)
jango [Routines]
Zeile 1: Zeile 1:
 =====Manager===== =====Manager=====
  
-The scripting system is initialised by creating one or more instances of the ScriptManager class. +Das Skriptsystem wird initialisiert, indem eine oder mehrere Instanzen der Klasse "Manager" erstellt werdenJede Instanz repräsentiert eine Skriptumgebung, in der Skripte geladen und ausgeführt werden könnenJede Instanz stellt außerdem einen globalen Variablenbereich bereit, über den die Skripte Daten austauschen können.
-Each instance represents a scripting environment where scripts can be loaded and executedEach +
-instance also provides a global variable scope that the scripts can use to share data.+
  
 <code csharp> <code csharp>
Zeile 11: Zeile 9:
 =====Script===== =====Script=====
  
-Once a script manager is availablescripts can be loaded by creating instances of the Script class. +Sobald ein Manager verfügbar istkönnen Skripte durch Erstellen von Instanzen der Klasse "Script" geladen werdenDer Konstruktor des Skriptobjekts benötigt eine Referenz auf den Skriptmanager und einen Namen zur Identifizierung des SkriptsStandardmäßig entspricht dieser Name einem Dateinamen auf der Festplatte.
-The script object's constructor requires a reference to the script manager and a name to identify +
-the scriptBy default, this name corresponds to a disk filename.+
  
 <code csharp> <code csharp>
Zeile 19: Zeile 15:
 </code> </code>
  
-The script object's constructor automatically compiles the script source into Conscript byte code. +Der Konstruktor des Skriptobjekts kompiliert den Skriptquellcode automatisch in Scriptstack-BytecodeStandardmäßig wird der generierte Bytecode mithilfe eines "PeepholeAssembleroptimierers optimiert. Debug Anweisungen werden hinzugefügt, um die Zuordnung des generierten Codes zum Originalquellcode zu erleichternDiese Einstellungen können über die Methoden "Debug" und "Optimise" des "Manager" gesteuert werden.
-By default, the generated byte code is optimised using a "peepholeassembly optimiser. Debug +
-instructions are added to facilitate mapping of the generated code with the original sourceThese +
-settings may be controlled by setting the ScriptManager's properties DebugMode and +
-OptimiseCode.+
  
 =====Interpreter===== =====Interpreter=====
  
-A script object represents only the programming instructions contained within and not its +Ein Skriptobjekt repräsentiert lediglich Programmanweisungen (sog Token), nicht aber seinen AusführungszustandUm das Skript auszuführenmuss eine Instanz der Klasse "Interpreter" erstellt werdenDer Konstruktor dieser Klasse benötigt eine Referenz auf das auszuführende Skript oder eine Referenz auf eine seiner FunktionenEine Skriptreferenz bewirkt die Ausführung der "main"-FunktionDer Skriptkontext ermöglicht die Ausführungssteuerung und den Zugriff auf den Ausführungszustandeinschließlich der während der Ausführung definierten Variablender nächsten auszuführenden Anweisung uswDie Klasse "Interpreter" repräsentiert eine laufende Instanz eines SkriptsDaher können mehrere Instanzen desselben Skriptobjekts innerhalb desselben Skriptmanagers ausgeführt werden, indem mehrere Interpreter erstellt werdendie auf dasselbe Skript verweisen.
-execution stateTo execute the scriptan instance of the ScriptContext class must be createdThe +
-class' constructor requires a reference to the script to be executed or a reference to one of the +
-script's functionsA script reference implies that the main function will be executedThe script +
-context provides execution controlas well as access to the execution state in terms of the variables +
-defined during executionthe next statement to be executed and so onThe ScriptContext class +
-represents a running instance of a scriptHencemultiple instances of the same script object can be +
-executed within the same script manager by creating multiple script contexts referencing the same +
-script.+
  
 <code csharp> <code csharp>
Zeile 45: Zeile 29:
  
 // create a context for one of the script's named functions // create a context for one of the script's named functions
-Function scriptFunction = script.Functions["WanderAround"];+Function scriptFunction = script.Functions["Just looking..."];
 Interpreter interpreter = new Interpreter(scriptFunction); Interpreter interpreter = new Interpreter(scriptFunction);
 </code> </code>
  
-The script context object allows execution of the referenced script via the three variants of its +Das Interpreter-Objekt ermöglicht die Ausführung des referenzierten Skripts über drei Varianten seiner "Interpret()"-Methodeunbegrenzte Ausführung, Ausführung innerhalb eines bestimmten Zeitintervalls oder Ausführung bis zu einer maximalen Anzahl ausgeführter AnweisungenDie erste Variante erlaubt die unbegrenzte Ausführung der referenzierten Skriptfunktion oder deren BeendigungEnthält das Skript eine Endlosschleife, blockiert diese Methode unbegrenztsofern keine Unterbrechung ausgelöst wirdDie "Interpret()"-Methode gibt die Gesamtzahl der seit ihrem Aufruf ausgeführten Anweisungen zurück.
-Execute method. These areexecution of scripts for an indefinite amount of time; execution of +
-scripts for a given time interval or execution of scripts for up to a maximum number of executed +
-statements. +
-The first method variant allows the referenced script function to execute indefinitely or until the +
-end of the function is reachedIf the script contains an infinite loopthis method will block +
-indefinitely unless an interrupt is generatedThe Execute method returns the total number of +
-statements executed since its invocation.+
  
 <code csharp> <code csharp>
Zeile 63: Zeile 40:
 </code> </code>
  
-The second variant of the Execute method allows the script context to execute up to a given +Die zweite Variante der "Interpret()"-Methode ermöglicht es dem Interpreter, bis zu einer vorgegebenen maximalen Anzahl von Anweisungen auszuführenDer Interpreter kann die Ausführung abbrechen, bevor das Maximum erreicht ist, wenn keine weiteren Anweisungen zu verarbeiten sind oder eine Unterbrechung ausgelöst wird.
-maximum number of statementsThe script context may break out of execution before the +
-maximum is reached if there are no more statements to process or if an interrupt is generated.+
  
 <code csharp> <code csharp>
Zeile 72: Zeile 47:
 </code> </code>
  
-The third variant of the Execute method accepts a TimeSpan defining the maximum time interval +Die dritte Variante der "Interpret()"-Methode akzeptiert einen TimeSpan, der das maximal zulässige Zeitintervall für die Skriptausführung definiertDie Methode kann die Ausführung vor Ablauf des angegebenen Intervalls abbrechen, wenn keine weiteren Anweisungen zu verarbeiten sind oder eine Unterbrechung ausgelöst wirdBei einem Skript mit einer ausgewogenen Anzahl verschiedener Anweisungen kann diese Methode beispielsweise verwendet werdenum die Geschwindigkeit des Skriptsystems in der Zielumgebung in Bezug auf die pro Sekunde ausgeführten Anweisungen zu ermitteln.
-allowed for script executionThe method may break out of execution earlier than the given interval +
-if there are no more statements to process or an interrupt is generatedGiven a script with a good +
-balance of different statementsa possible use of this method is to determine the speed of the +
-scripting system on the target environment in terms of statements executed per second.+
  
 <code csharp> <code csharp>
Zeile 84: Zeile 55:
 </code> </code>
  
-The second and third variants of Execute may be used to implement a virtual multi-threaded 
-scripting environment. Global variables may be used as semaphores to synchronise concurrently 
-running scripts. 
  
-A script context will normally execute its referenced script function indefinitelyfor a given time +Ein Interpreter führt seine referenzierte Skriptfunktion normalerweise unbegrenzt für ein bestimmtes Zeitintervall ausbis eine maximale Anzahl von Anweisungen ausgeführt wurde oder keine weiteren Anweisungen mehr zu verarbeiten sind. In manchen Fällen ist es jedoch wünschenswertdie Ausführung vorzeitig abzubrechenbeispielsweise um die Kontrolle an den Host zurückzugeben, sobald bestimmte Anweisungen ausgeführt wurden, oder weil ein Skript zu rechenintensiv ist, um es in einem Durchgang auszuführen. 
-interval, until a given maximum number of statements are executed or until there are no more +
-statements to process. In some cases it is desirable to break execution prematurelysuch as to +
-return control to the host when specific statements are executedor because a script is too +
-computationally intensive to execute in one go.+
 Conscript provides two ways for generating script interrupts: Conscript provides two ways for generating script interrupts:
  
Zeile 100: Zeile 65:
 =====Scanner===== =====Scanner=====
  
-To allow for loading of scripts from other sources -- such as an archive filenetwork or database -- +Um das Laden von Skripten aus anderen Quellen wie Archivdateiendem Netzwerk oder Datenbanken zu ermöglichen, kann ein benutzerdefinierter Scanner an den Manager gebunden werdenDieser Scanner kann jede Klasse sein, die das Interface `Scanner` implementiert
-a custom script loader class can be developed and bound to the script manager to be used for +
-loading the scriptThe script loader class may be any class that implements the ScriptLoader +
-interface. The loader is used to retrieve the script specified in the Script class constructor and also +
-any additional include scripts defined within the original script.+
  
 <code csharp> <code csharp>
Zeile 124: Zeile 85:
 =====Variablen===== =====Variablen=====
  
-One approach for allowing a script to communicate with or control the host application entails the +Eine Möglichkeit, einem Skript die Kommunikation mit der Hostanwendung oder deren Steuerung zu ermöglichen, besteht darin, dass die Anwendung die lokalen Variablen des zugehörigen Interpreters und die globalen Variablen des zugehörigen Managers abfragtDies geschieht durch Abfragen der "LocalMemory"-Eigenschaft des "Interpreter"-Objektsder "ScriptMemory"-Eigenschaft des "Script"-Objekts oder der "GlobalMemory"-Eigenschaft des "Manager"-Objekts.
-application polling the local variables of the associated script context and global variables of the +
-associated script managerIt does this by querying the LocalDictionary property of the +
-ScriptContext objectthe ScriptDictionary property of the Script object or the +
-GlobalDicitonary property of the ScriptManager object.+
  
 <code csharp> <code csharp>
Zeile 155: Zeile 112:
 <code csharp> <code csharp>
 // define route // define route
-Routine routine = new Routine( +Routine routine = new Routine((Type)null, "Print", (Type)null, "A function to print text");
- (Type)null, "Print", (Type)null, "A function to print text");+
 </code> </code>
  
Zeile 172: Zeile 128:
 listParameterTypes.Add(typeof(ArrayList)); listParameterTypes.Add(typeof(ArrayList));
  
-// define function prototype with many parameters +// define routine with many parameters 
-Routine routine = new Routine( +Routine routine = new Routine((Type)null, "Print", listParameterTypes);
- (Type)null, "Print", listParameterTypes);+
 </code> </code>
  
Zeile 198: Zeile 153:
 public class Program : Host public class Program : Host
 { {
- // class implementation + 
- private Interpreter interpreter; +    private Interpreter interpreter; 
- public Main(script script) + 
- { +    public Main(script script) 
- interpreter = new Interpreter(script); +    
- interpreter.Handler = this; +        interpreter = new Interpreter(script); 
- } +        interpreter.Handler = this; 
- public object Invoke(String functionName, List<object> parameters) +    
- { +  
- if (functionName == "Print"+    public object Invoke(String functionName, List<object> parameters) 
- { +    
- string str = (int)listParameters[0]; +        if (functionName == "Print"
- Console.WriteLine(str); +        
- return; +            string str = (int)parameters[0]; 
- } +            Console.WriteLine(str); 
- return null; +            return; 
- }+        
 +        return null; 
 +    } 
 +     
 +}
 </code> </code>
  
Zeile 227: Zeile 186:
 <code csharp> <code csharp>
 // register global Sine function // register global Sine function
-HostFunctionPrototype hostFunctionPrototype = new HostFunctionPrototype( +Routine routine = new Routine(typeof(float), "Print", typeof(float)); 
- typeof(float), "Sin", typeof(float)); +manager.Register(routineprintHandler); 
-m_scriptManager.RegisterHostFunction(hostFunctionPrototypetrigHandler);+
 // register global Cosine function // register global Cosine function
-HostFunctionPrototype hostFunctionPrototype = new HostFunctionPrototype( +routine = new Routine(typeof(float), "Read", typeof(float)); 
- typeof(float), "Cos", typeof(float)); +manager.Register(routinereadHandler);
-m_scriptManager.RegisterHostFunction(hostFunctionPrototype, trigHandler); +
-// register global Tangent function +
-HostFunctionPrototype hostFunctionPrototype = new HostFunctionPrototype( +
- typeof(float), "Tan", typeof(float)); +
-m_scriptManager.RegisterHostFunction(hostFunctionPrototypetrigHandler);+
 </code> </code>
  
scriptstack.1765761568.txt.gz · Zuletzt geändert: 2025/12/15 02:19 von jango