public void PushNewValueObject(IntPtr luaState, object o, int index) { LuaAPI.luanet_newudata(luaState, index); Type t = o.GetType(); PushMetaTable(luaState, o.GetType()); if (LuaAPI.lua_isnil(luaState, -1)) { string meta = t.AssemblyQualifiedName; Debugger.LogWarning("Create not wrap ulua type:" + meta); LuaAPI.lua_settop(luaState, -2); LuaAPI.luaL_newmetatable(luaState, meta); LuaAPI.lua_pushstring(luaState, "cache"); LuaAPI.lua_newtable(luaState); LuaAPI.lua_rawset(luaState, -3); LuaAPI.lua_pushlightuserdata(luaState, LuaAPI.luanet_gettag()); LuaAPI.lua_pushnumber(luaState, 1); LuaAPI.lua_rawset(luaState, -3); LuaAPI.lua_pushstring(luaState, "__index"); LuaAPI.lua_pushstring(luaState, "luaNet_indexfunction"); LuaAPI.lua_rawget(luaState, LuaAPI.LUA_REGISTRYINDEX); LuaAPI.lua_rawset(luaState, -3); LuaAPI.lua_pushstring(luaState, "__gc"); LuaAPI.lua_pushstdcallcfunction(luaState, metaFunctions.gcFunction); LuaAPI.lua_rawset(luaState, -3); LuaAPI.lua_pushstring(luaState, "__tostring"); LuaAPI.lua_pushstdcallcfunction(luaState, metaFunctions.toStringFunction); LuaAPI.lua_rawset(luaState, -3); LuaAPI.lua_pushstring(luaState, "__newindex"); LuaAPI.lua_pushstdcallcfunction(luaState, metaFunctions.newindexFunction); LuaAPI.lua_rawset(luaState, -3); } LuaAPI.lua_setmetatable(luaState, -2); }
private void createFunctionMetatable(IntPtr luaState) { LuaAPI.luaL_newmetatable(luaState, "luaNet_function"); LuaAPI.lua_pushstring(luaState, "__gc"); LuaAPI.lua_pushstdcallcfunction(luaState, metaFunctions.gcFunction); LuaAPI.lua_settable(luaState, -3); LuaAPI.lua_pushstring(luaState, "__call"); LuaAPI.lua_pushstdcallcfunction(luaState, metaFunctions.execDelegateFunction); LuaAPI.lua_settable(luaState, -3); LuaAPI.lua_settop(luaState, -2); }
private void createBaseClassMetatable(IntPtr luaState) { LuaAPI.luaL_newmetatable(luaState, "luaNet_searchbase"); LuaAPI.lua_pushstring(luaState, "__gc"); LuaAPI.lua_pushstdcallcfunction(luaState, metaFunctions.gcFunction); LuaAPI.lua_settable(luaState, -3); LuaAPI.lua_pushstring(luaState, "__tostring"); LuaAPI.lua_pushstdcallcfunction(luaState, metaFunctions.toStringFunction); LuaAPI.lua_settable(luaState, -3); LuaAPI.lua_pushstring(luaState, "__index"); LuaAPI.lua_pushstdcallcfunction(luaState, metaFunctions.baseIndexFunction); LuaAPI.lua_settable(luaState, -3); LuaAPI.lua_pushstring(luaState, "__newindex"); LuaAPI.lua_pushstdcallcfunction(luaState, metaFunctions.newindexFunction); LuaAPI.lua_settable(luaState, -3); LuaAPI.lua_settop(luaState, -2); }
private void createClassMetatable(IntPtr luaState) { LuaAPI.luaL_newmetatable(luaState, "luaNet_class"); LuaAPI.lua_pushstring(luaState, "__gc"); LuaAPI.lua_pushstdcallcfunction(luaState, metaFunctions.gcFunction); LuaAPI.lua_settable(luaState, -3); LuaAPI.lua_pushstring(luaState, "__tostring"); LuaAPI.lua_pushstdcallcfunction(luaState, metaFunctions.toStringFunction); LuaAPI.lua_settable(luaState, -3); LuaAPI.lua_pushstring(luaState, "__index"); LuaAPI.lua_pushstdcallcfunction(luaState, metaFunctions.classIndexFunction); LuaAPI.lua_settable(luaState, -3); LuaAPI.lua_pushstring(luaState, "__newindex"); LuaAPI.lua_pushstdcallcfunction(luaState, metaFunctions.classNewindexFunction); LuaAPI.lua_settable(luaState, -3); LuaAPI.lua_pushstring(luaState, "__call"); LuaAPI.lua_pushstdcallcfunction(luaState, metaFunctions.callConstructorFunction); LuaAPI.lua_settable(luaState, -3); LuaAPI.lua_settop(luaState, -2); }