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:
Kayne Ruse
2014-11-23 06:38:40 +11:00
parent 20d40d5b81
commit 5eeda8235d
5 changed files with 69 additions and 11 deletions
+32
View File
@@ -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}
};