public static void wlua_pushcclosure(IntPtr luaState, LuaCSFunction f, int nup) { LuaDLL.wlua_getglobal(luaState, "cswrapfunc"); //nup,wrap LuaDLL.lua_insert(luaState, -nup - 1); //wrap,nup LuaDLL.lua_pushcclosure(luaState, f, nup); //wrap,f0 LuaDLL.lua_pcall(luaState, 1, 1, 0); //f }
//index: cswrapfunc index //efficiently than wlua_pushcfunction due to not pop wrapfunc public static void wLua_wrapfunction(IntPtr L, int index, LuaCSFunction f, bool isOctr = false) { LuaDLL.lua_pushvalue(L, index); //cswrapfunc LuaDLL.lua_pushcclosure(L, f, 0); //cswrapfunc,f if (isOctr) { LuaDLL.lua_pushboolean(L, true); //cswrapfunc,f,b } LuaDLL.lua_pcall(L, isOctr ? 2 : 1, 1, 0); // no error should be returned }
public void LuaPushFunction(LuaCSFunction func) { IntPtr fn = Marshal.GetFunctionPointerForDelegate(func); LuaDLL.lua_pushcclosure(L, fn, 0); }
public void LuaPushCClosure(IntPtr fn, int n) { LuaDLL.lua_pushcclosure(L, fn, n); }
public static void lua_pushcfunction(IntPtr luaState, LuaCSFunction func) { IntPtr functionPointerForDelegate = Marshal.GetFunctionPointerForDelegate(func); LuaDLL.lua_pushcclosure(luaState, functionPointerForDelegate, 0); }
public static void lua_pushcsfunction(IntPtr luaState, LuaCSFunction function) { LuaDLL.lua_getref(luaState, SLua.LuaState.PCallCSFunctionRef); LuaDLL.lua_pushcclosure(luaState, Marshal.GetFunctionPointerForDelegate(function), 0); LuaDLL.lua_call(luaState, 1, 1); }