Fixed the table inheritance which was backwards

This commit is contained in:
2016-04-11 00:08:42 +10:00
parent 752f8f82f9
commit 8e7af9ce88
4 changed files with 25 additions and 18 deletions
+7
View File
@@ -26,6 +26,12 @@
print("Lua script check") print("Lua script check")
entityAPI = require("entity")
for k, v in pairs(entityAPI) do
print(k, v)
end
--requirements --requirements
roomManagerAPI = require("room_manager") roomManagerAPI = require("room_manager")
roomAPI = require("room") roomAPI = require("room")
@@ -114,3 +120,4 @@ roomAPI.Initialize(underworld, mapSaver.Load, mapSaver.Save, mapMaker.DebugGrass
--call the monstrosity --call the monstrosity
doorUtility.CreateDoorPair("pair 1", overworld, -64, -64, underworld, 64, 64) doorUtility.CreateDoorPair("pair 1", overworld, -64, -64, underworld, 64, 64)
+6 -6
View File
@@ -102,27 +102,27 @@ static const luaL_Reg characterLib[] = {
}; };
LUAMOD_API int openCharacterAPI(lua_State* L) { LUAMOD_API int openCharacterAPI(lua_State* L) {
//get the parent table
luaL_requiref(L, TORTUGA_ENTITY_API, openEntityAPI, false);
//the local table //the local table
luaL_newlib(L, characterLib); luaL_newlib(L, characterLib);
//merge the local table into the parent table //get the parent table
luaL_requiref(L, TORTUGA_ENTITY_API, openEntityAPI, false);
//merge the parent table into the local table
lua_pushnil(L); //first key lua_pushnil(L); //first key
while(lua_next(L, -2)) { while(lua_next(L, -2)) {
//copy the key-value pair //copy the key-value pair
lua_pushvalue(L, -2); lua_pushvalue(L, -2);
lua_pushvalue(L, -2); lua_pushvalue(L, -2);
//push the copy to the parent table //push the copy to the local table
lua_settable(L, -6); lua_settable(L, -6);
//pop the original value before continuing //pop the original value before continuing
lua_pop(L, 1); lua_pop(L, 1);
} }
//remove the local table, leaving the expanded parent table //remove the parent table, leaving the expanded local table
lua_pop(L, 1); lua_pop(L, 1);
return 1; return 1;
+6 -6
View File
@@ -75,27 +75,27 @@ static const luaL_Reg barrierLib[] = {
}; };
LUAMOD_API int openBarrierAPI(lua_State* L) { LUAMOD_API int openBarrierAPI(lua_State* L) {
//get the parent table
luaL_requiref(L, TORTUGA_ENTITY_API, openEntityAPI, false);
//the local table //the local table
luaL_newlib(L, barrierLib); luaL_newlib(L, barrierLib);
//merge the local table into the parent table //get the parent table
luaL_requiref(L, TORTUGA_ENTITY_API, openEntityAPI, false);
//merge the parent table into the local table
lua_pushnil(L); //first key lua_pushnil(L); //first key
while(lua_next(L, -2)) { while(lua_next(L, -2)) {
//copy the key-value pair //copy the key-value pair
lua_pushvalue(L, -2); lua_pushvalue(L, -2);
lua_pushvalue(L, -2); lua_pushvalue(L, -2);
//push the copy to the parent table //push the copy to the local table
lua_settable(L, -6); lua_settable(L, -6);
//pop the original value before continuing //pop the original value before continuing
lua_pop(L, 1); lua_pop(L, 1);
} }
//remove the local table, leaving the expanded parent table //remove the parent table, leaving the expanded local table
lua_pop(L, 1); lua_pop(L, 1);
return 1; return 1;
+6 -6
View File
@@ -76,27 +76,27 @@ static const luaL_Reg creatureLib[] = {
}; };
LUAMOD_API int openCreatureAPI(lua_State* L) { LUAMOD_API int openCreatureAPI(lua_State* L) {
//get the parent table
luaL_requiref(L, TORTUGA_ENTITY_API, openEntityAPI, false);
//the local table //the local table
luaL_newlib(L, creatureLib); luaL_newlib(L, creatureLib);
//merge the local table into the parent table //get the parent table
luaL_requiref(L, TORTUGA_ENTITY_API, openEntityAPI, false);
//merge the parent table into the local table
lua_pushnil(L); //first key lua_pushnil(L); //first key
while(lua_next(L, -2)) { while(lua_next(L, -2)) {
//copy the key-value pair //copy the key-value pair
lua_pushvalue(L, -2); lua_pushvalue(L, -2);
lua_pushvalue(L, -2); lua_pushvalue(L, -2);
//push the copy to the parent table //push the copy to the local table
lua_settable(L, -6); lua_settable(L, -6);
//pop the original value before continuing //pop the original value before continuing
lua_pop(L, 1); lua_pop(L, 1);
} }
//remove the local table, leaving the expanded parent table //remove the parent table, leaving the expanded local table
lua_pop(L, 1); lua_pop(L, 1);
return 1; return 1;