private static void Test1(DWSContext context) { var t = new DWSTypeDefinition("TPoint"); t.Fields.Add(new DWSFieldDefinition("x", "Integer")); t.Fields.Add(new DWSFieldDefinition("y", "Integer")); var m = new DWSMethodDefinition("ReturnFirstArg", (c, a) => { var v = c.CreateTypedValue("TPoint"); object o = v.Value; v["x"] = 10; return(v); }); m.Args.Add(new DWSParameterDefinition("a", "Integer")); m.ReturnTypeName = "TPoint"; context.DefineType(t); context.DefineMethod(m); string s = context.EvaluateScript("var t : TPoint = ReturnFirstArg(2); ReturnFirstArg(t.x);"); GC.KeepAlive(m); }
private static void Test3(DWSContext context) { var a = new DWSArrayDefinition("TIntArray", "Integer"); context.DefineType(a); var method = new DWSMethodDefinition("CreateArrayTest", new NativeAction(CreteArrayTest)); context.DefineMethod(method); context.EvaluateScript("CreateArrayTest();"); GC.KeepAlive(method); }
private static void Test2(DWSContext context) { ThreadPool.QueueUserWorkItem(x => { Thread.Sleep(5000); context.Stop(); }); // run infinite loop string s = context.EvaluateScript(@" var i : float = 0; while i <= 0 do begin i := i - 0.000001; end;"); }
private static void Test4(DWSContext context) { var a = new DWSEnumDefinition("TEnum"); a.Add("ENUM_VALUE1", 0); a.Add("ENUM_VALUE2", 1); a.Add("ENUM_VALUE3", 2); context.DefineType(a); var method = new DWSMethodDefinition("CreateArrayTest", new NativeAction((cx, args) => { var v = new DWSElement(args[0]); bool s = false; })); method.Args.Add(new DWSParameterDefinition("a", "TEnum") { DefaultValue = "ENUM_VALUE3" }); context.DefineMethod(method); context.EvaluateScript("CreateArrayTest();"); GC.KeepAlive(method); }