public void RunScript() { if (!srm.HasStdOutputListener(this)) { srm.AddStdOutputListener(this); } try { CompiledScript cs = srm.Compile(editor.Text); object v = srm.RunCompiledScript(cs); if (ScriptExecuted != null) { ScriptExecuted(this, null); } timer.Enabled = true; //LogValue(v); } catch (Exception ex) { Log("error: " + ex.Message); } }
/// <summary> /// This example shows how to get the information about functions and variables that /// is written in script from .NET program. /// /// ReoScript provides the ability to get functions and variables information after /// script is compiling. /// /// To use this feature you have to use the following namespaces: /// /// - Unvell.ReoScript /// - Unvell.ReoScript.Reflection /// /// The script's instruction information returned in a tree-style: /// /// CompiledScript /// +- Functions /// +- Functions /// +- Functions /// +- Variables /// +- Variables /// +- Variables /// </summary> /// <param name="args"></param> static void Main(string[] args) { string script = @" function normal() { return 'normal function'; } function outer(p1, p2, p3, p4) { function inner(key, value) { var local = 10; function inner2(param) { } } return function(a, b) { return a + b; } (); } var af = function(x, y) { return x * y; }; var result = af(2, 5); " ; ScriptRunningMachine srm = new ScriptRunningMachine(); CompiledScript cs = srm.Compile(script, true); Console.WriteLine("Functions: "); Console.WriteLine(); foreach (FunctionInfo fi in cs.DeclaredFunctions) { IterateFunction(fi, 0); } Console.WriteLine("Global Variables: "); Console.WriteLine(); foreach (VariableInfo vi in cs.DeclaredVariables) { PrintOutLine("Variable Name", vi.Name, 0); PrintOutLine(" Has Initial Value", vi.HasInitialValue.ToString(), 0); PrintOutLine(" Position", vi.Line + ":" + vi.CharIndex, 0); Console.WriteLine(); } #if DEBUG Console.WriteLine("Press any key to continue..."); Console.ReadKey(); #endif }
/// <summary> /// This example shows how to get the information about functions and variables that /// is written in script from .NET program. /// /// ReoScript provides the ability to get functions and variables information after /// script is compiling. /// /// To use this feature you have to use the following namespaces: /// /// - Unvell.ReoScript /// - Unvell.ReoScript.Reflection /// /// The script's instruction information returned in a tree-style: /// /// CompiledScript /// +- Functions /// +- Functions /// +- Functions /// +- Variables /// +- Variables /// +- Variables /// </summary> /// <param name="args"></param> static void Main(string[] args) { string script = @" function normal() { return 'normal function'; } function outer(p1, p2, p3, p4) { function inner(key, value) { var local = 10; function inner2(param) { } } return function(a, b) { return a + b; } (); } var af = function(x, y) { return x * y; }; var result = af(2, 5); "; ScriptRunningMachine srm = new ScriptRunningMachine(); CompiledScript cs = srm.Compile(script, true); Console.WriteLine("Functions: "); Console.WriteLine(); foreach (FunctionInfo fi in cs.DeclaredFunctions) { IterateFunction(fi, 0); } Console.WriteLine("Global Variables: "); Console.WriteLine(); foreach (VariableInfo vi in cs.DeclaredVariables) { PrintOutLine("Variable Name", vi.Name, 0); PrintOutLine(" Has Initial Value", vi.HasInitialValue.ToString(), 0); PrintOutLine(" Position", vi.Line + ":" + vi.CharIndex, 0); Console.WriteLine(); } #if DEBUG Console.WriteLine("Press any key to continue..."); Console.ReadKey(); #endif }