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); }
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); }