Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Request some example codes on these new features
#2
Type/click CsScript or CsExec etc in the code editor and press F1.

Some examples copied from there:
Macro Macro2068
Code:
Copy      Help
;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")


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)