Exemple #1
0
 public void callTest()
 {
     CSLua.LuaState L = new CSLua.LuaState();
     L.dostring("square = function(x) return x*x end");
     CSLua.MultiValue result = L.call("square", 12.0);
     Assert.AreEqual(144.0, result[0]);
 }
Exemple #2
0
        public void classTest()
        {
            CSLua.LuaState L            = new CSLua.LuaState();
            var            setterGetter = new SetterGetter();

            setterGetter.SetNumber(1234.567);
            setterGetter.SetString("this is a test");
            L.registerObject("testObject", setterGetter);
            {
                var result = L.dostring("return testObject:GetNumber()");
                Assert.AreEqual(1234.567, result[0]);
            }

            {
                var result = L.dostring("return testObject:GetString()");
                Assert.AreEqual("this is a test", result[0]);
            }

            {
                L.dostring("testObject:SetNumber(394856.32)");
                Assert.AreEqual(394856.32, setterGetter.GetNumber());
            }
            {
                L.dostring("testObject:SetString(\"Yet Another String\")");
                Assert.AreEqual("Yet Another String", setterGetter.GetString());
            }
        }
Exemple #3
0
        public void registerFunctionAsFuncTest()
        {
            CSLua.LuaState L = new CSLua.LuaState();
            L.registerFunctionAs((Func <double, double>)NOTSquare, "sqr");
            var result = L.dostring("return sqr(3.3)");

            Assert.AreEqual(10.89, (double)result[0], 0.00001);
        }
Exemple #4
0
 public void registerFunctionActionOneParamTest()
 {
     CSLua.LuaState L = new CSLua.LuaState();
     mTestActionCalled = false;
     L.registerFunction((Action <string>)TestActionOneParam);
     L.call("TestActionOneParam", "This is a param");
     Assert.AreEqual("This is a param", mTestActionOneParamParam);
 }
Exemple #5
0
 public void registerFunctionActionTest()
 {
     CSLua.LuaState L = new CSLua.LuaState();
     mTestActionCalled = false;
     L.registerFunction((Action)TestAction);
     L.call("TestAction");
     Assert.IsTrue(mTestActionCalled);
 }
Exemple #6
0
        public void registerFunctionDelegateFuncTest()
        {
            CSLua.LuaState L = new CSLua.LuaState();
            L.registerFunction((Delegate)(Func <double, double>)NOTSquare);
            var result   = L.dostring("return Square(32.623)");
            var expected = 1064.260129;

            Assert.AreEqual(expected, (double)result[0], 0.00001);
        }
Exemple #7
0
        public void registerFunctionAsLambdaTest()
        {
            // This test is disabled because lambda expressions don't register correctly.
            // This is due to LuaState only assuming that all non-static methods are members of an object
            // and must be called from lua using the : syntax (passing the object as the first argument).
            // Lambda functions are not static, and they contain their object, but this is not yet supported.

            CSLua.LuaState L = new CSLua.LuaState();
            L.registerFunctionAs((Func <double, double>)(x => x * x), "sqr");
            var result = L.dostring("return sqr(4.0)");

            Assert.AreEqual(16.0, (double)result[0], 0.00001);
        }
Exemple #8
0
        public void registerObjectTest()
        {
            CSLua.LuaState L          = new CSLua.LuaState();
            Multiplier     multiplier = new Multiplier("MyMult");

            L.registerObject("testObject", multiplier);

            CSLua.MultiValue result = L.dostring("return testObject:multiply(7, 13)");
            Assert.AreEqual(91.0, result[0]);

            result = L.dostring("return testObject:multiply(1, 1)");
            Assert.AreEqual(1.0, result[0]);

            result = L.dostring("return testObject:multiply(100001, 7)");
            Assert.AreEqual(700007.0, result[0]);
        }
Exemple #9
0
        public void unRegisterObjectTest()
        {
            // unregisterObject is not yet implemented.

            CSLua.LuaState L          = new CSLua.LuaState();
            Multiplier     multiplier = new Multiplier("MyMult");

            L.registerObject("testObject", multiplier);

            {
                var result = L.dostring("return testObject:multiply(1, 1)");
                Assert.AreEqual(1.0, result[0]);
            }

            // This is not yet implemented
            L.unregisterObject(multiplier);

            {
                var result = L.dostring("return testObject:multiply(1, 1)");
                Assert.AreEqual(null, result[0]);
            }
        }
Exemple #10
0
 public void stringTest()
 {
     CSLua.LuaState   L      = new CSLua.LuaState();
     CSLua.MultiValue result = L.dostring("return \"This is a string\"");
     Assert.AreEqual("This is a string", result[0]);
 }
Exemple #11
0
 public void numberTest()
 {
     CSLua.LuaState   L      = new CSLua.LuaState();
     CSLua.MultiValue result = L.dostring("return 1");
     Assert.AreEqual(1.0, result[0]);
 }
Exemple #12
0
 public void dostringTest()
 {
     CSLua.LuaState   L      = new CSLua.LuaState();
     CSLua.MultiValue result = L.dostring("return \"Hello World\"");
     Assert.AreEqual("Hello World", result[0]);
 }