LuaInterface.LuaDLL.lua_pushcfunction C# (CSharp) Method

lua_pushcfunction() public static method

public static lua_pushcfunction ( IntPtr luaState, LuaCSFunction function ) : void
luaState System.IntPtr
function LuaCSFunction
return void
        public static void lua_pushcfunction(IntPtr luaState, LuaCSFunction function)
        {
#if SLUA_STANDALONE
            // Add all LuaCSFunction¡ê? or they will be GC collected!  (problem at windows, .net framework 4.5, `CallbackOnCollectedDelegated` exception)
            GCHandle.Alloc(function);
#endif
            IntPtr fn = Marshal.GetFunctionPointerForDelegate(function);
            lua_pushcclosure(luaState, fn, 0);
        }

Usage Example

示例#1
0
        public static void OpenLibs(IntPtr L)
        {
            LuaDLL.lua_getglobal(L, "tolua");
            LuaDLL.lua_pushstring(L, "findtype");
            LuaDLL.lua_pushcfunction(L, new LuaCSFunction(LuaReflection.FindType));
            LuaDLL.lua_rawset(L, -3);
            LuaDLL.lua_pushstring(L, "loadassembly");
            LuaDLL.tolua_pushcfunction(L, new LuaCSFunction(LuaReflection.LoadAssembly));
            LuaDLL.lua_rawset(L, -3);
            LuaDLL.lua_pushstring(L, "getmethod");
            LuaDLL.tolua_pushcfunction(L, new LuaCSFunction(LuaReflection.GetMethod));
            LuaDLL.lua_rawset(L, -3);
            LuaDLL.lua_pushstring(L, "getconstructor");
            LuaDLL.tolua_pushcfunction(L, new LuaCSFunction(LuaReflection.GetConstructor));
            LuaDLL.lua_rawset(L, -3);
            LuaDLL.lua_pushstring(L, "gettypemethod");
            LuaDLL.tolua_pushcfunction(L, new LuaCSFunction(LuaReflection.GetTypeMethod));
            LuaDLL.lua_rawset(L, -3);
            LuaDLL.lua_pushstring(L, "getfield");
            LuaDLL.tolua_pushcfunction(L, new LuaCSFunction(LuaReflection.GetField));
            LuaDLL.lua_rawset(L, -3);
            LuaDLL.lua_pushstring(L, "getproperty");
            LuaDLL.tolua_pushcfunction(L, new LuaCSFunction(LuaReflection.GetProperty));
            LuaDLL.lua_rawset(L, -3);
            LuaDLL.lua_pushstring(L, "createinstance");
            LuaDLL.tolua_pushcfunction(L, new LuaCSFunction(LuaReflection.CreateInstance));
            LuaDLL.lua_rawset(L, -3);
            LuaDLL.lua_pop(L, 1);
            LuaState luaState = LuaState.Get(L);

            luaState.BeginPreLoad();
            luaState.AddPreLoad("tolua.reflection", new LuaCSFunction(LuaReflection.OpenReflectionLibs));
            luaState.EndPreLoad();
        }
All Usage Examples Of LuaInterface.LuaDLL::lua_pushcfunction
LuaDLL