Beispiel #1
0
        static void SimpleFunctionCalls()
        {
            Console.Write("\nSimple function calls ");
            Engine engine = CreateEngine();

            Assert(engine.XCall("dumpvar", true, 5, "test"), 1);
            Assert(engine.StackItem(-1).GetString(), "bool (true)\nint (5)\nstring [4] \"test\"\n");
            engine.Pop(1);

            Assert(engine.Exec("function this2string(){ return tostring(this); }"), 0);
            Assert(engine.XThisCall(engine.GetGlobal("this2string"), engine.GetGlobal("dumpvar")), 1);
            Assert(engine.StackItem(-1).GetString(), "C function");
            engine.Pop(1);

            Assert(engine.ACall("dumpvar", "roundtrip")[0], "string [9] \"roundtrip\"\n");
            Assert(engine.AThisCall(engine.GetGlobal("this2string"), "roundtrip")[0], "roundtrip");

            Assert(engine.OCall("dumpvar", "roundtrip"), "string [9] \"roundtrip\"\n");
            Assert(engine.OThisCall(engine.GetGlobal("this2string"), "roundtrip"), "roundtrip");

            Assert(engine.Call <string>("dumpvar", "roundtrip"), "string [9] \"roundtrip\"\n");
            Assert(engine.ThisCall <string>(engine.GetGlobal("this2string"), "roundtrip"), "roundtrip");

            DestroyEngine(engine);
        }