/// <summary> /// Registers a .net method denoted by the delegate Lua.LuaFunction as a lua function /// the function will take on the name luaFuncName, in lua /// </summary> /// <param name="func">.net function to register with lua</param> /// <param name="luaFuncName">name of .net function in lua</param> public void RegisterLuaFunction(Lua.LuaFunction func, string luaFuncName) { Lua.lua_pushcfunction(L, func); Lua.lua_setglobal(L, luaFuncName); //Lua.lua_register(m_lua_State, luaFuncName, func); //make sure the delegate callback is not collected by the garbage collector before //unmanaged code has called back m_refs.Add(func); }
/// <summary> /// Creates a table with tableName if it does not already exist. /// After creation or if the table already exists, stack will be empty and balanced. /// </summary> /// <param name="tableName"></param> public void CreateLuaTable(string tableName) { Lua.lua_getglobal(L, tableName); if (IsTopNil) { //remove the nil value Lua.lua_pop(L, 1); Lua.lua_newtable(L); Lua.lua_setglobal(L, tableName); //stack is empty } else { //remove the existing table from the stack Lua.lua_pop(L, 1); } }