Fixed the scripts struggling with nested API tables
I actually don't remember what the RoomData's lua references where for, but I'm pretty srue it wasn't this. I'll figure something out when I've had a sleep.
This commit is contained in:
@@ -55,12 +55,44 @@ static int getPager(lua_State* L) {
|
||||
|
||||
//TODO: GetEntityList?
|
||||
|
||||
static int setLoadReference(lua_State* L) {
|
||||
RoomData* room = reinterpret_cast<RoomData*>(lua_touserdata(L, 1));
|
||||
luaL_unref(L, LUA_REGISTRYINDEX, room->GetLoadReference());
|
||||
room->SetLoadReference(luaL_ref(L, LUA_REGISTRYINDEX));
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int getLoadReference(lua_State* L) {
|
||||
RoomData* room = reinterpret_cast<RoomData*>(lua_touserdata(L, 1));
|
||||
lua_pushinteger(L, room->GetLoadReference());
|
||||
lua_gettable(L, LUA_REGISTRYINDEX);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int setUnloadReference(lua_State* L) {
|
||||
RoomData* room = reinterpret_cast<RoomData*>(lua_touserdata(L, 1));
|
||||
luaL_unref(L, LUA_REGISTRYINDEX, room->GetUnloadReference());
|
||||
room->SetUnloadReference(luaL_ref(L, LUA_REGISTRYINDEX));
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int getUnloadReference(lua_State* L) {
|
||||
RoomData* room = reinterpret_cast<RoomData*>(lua_touserdata(L, 1));
|
||||
lua_pushinteger(L, room->GetUnloadReference());
|
||||
lua_gettable(L, LUA_REGISTRYINDEX);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static const luaL_Reg roomLib[] = {
|
||||
{"GetPager",getPager},
|
||||
{"SetRoomName", setRoomName},
|
||||
{"GetRoomName", getRoomName},
|
||||
{"SetTileset", setTilesetName},
|
||||
{"GetTileset", getTilesetName},
|
||||
{"SetOnLoad", setLoadReference},
|
||||
{"GetOnLoad", getLoadReference},
|
||||
{"SetOnUnload", setUnloadReference},
|
||||
{"GetOnUnload", getUnloadReference},
|
||||
{nullptr, nullptr}
|
||||
};
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@ int openRoomSystemAPI(lua_State* L) {
|
||||
|
||||
//push the substable
|
||||
for (const luaL_Reg* lib = libs; lib->func; lib++) {
|
||||
lua_pushcfunction(L, lib->func);
|
||||
lib->func(L);
|
||||
lua_setfield(L, -2, lib->name);
|
||||
}
|
||||
return 1;
|
||||
|
||||
Reference in New Issue
Block a user