07-04-2013, 05:01 PM
Type/click CsScript or CsExec etc in the code editor and press F1.
Some examples copied from there:
Macro Macro2068
Some examples copied from there:
Macro Macro2068
;Use CsExec to execute script containing function Main, like to run program compiled from this code.
str code=
;using System;
;public class Class1
;{
;;;;;static void Main(string[] a)
;;;;;{
;;;;;;;;;int i;
;;;;;;;;;for(i=0; i<a.Length; i++) Console.Write(a[i]);
;;;;;}
;}
CsExec code "called Main"
;__________________________________________________
;Use CsFunc to call single static function once.
str code2=
;using System;
;public class Class1
;{
;;;;;static public string StaticFunc(string s)
;;;;;{
;;;;;;;;;Console.Write(s);
;;;;;;;;;return "something";
;;;;;}
;}
str R=CsFunc(code2 "called StaticFunc using CsFunc")
out R
;__________________________________________________
;Use CsScript class when want to call multiple functions, create objects, set options, call functions faster, create or load .dll or .exe files.
str code3=
;using System;
;public class Class1
;{
;;;;;static public string StaticFunc(string s)
;;;;;{
;;;;;;;;;Console.Write(s);
;;;;;;;;;return "something";
;;;;;}
;;;;;public int Func1(int a, int b)
;;;;;{
;;;;;;;;;return a+b;
;;;;;}
;;;;;public string Func2(string a, string b)
;;;;;{
;;;;;;;;;return a+b;
;;;;;}
;}
CsScript x.AddCode(code3)
;call static function
str R2=x.Call("Class1.StaticFunc" "called StaticFunc using CsScript.Call")
;create object and call non-static function
IDispatch obj=x.CreateObject("Class1")
out obj.Func1(2 3)
out obj.Func2("2" "3")