Skip to content

Commit

Permalink
Address various issues
Browse files Browse the repository at this point in the history
Co-authored-by: sfan5 <sfan5@live.de>
  • Loading branch information
y5nw and sfan5 committed Feb 16, 2024
1 parent 855d30a commit fb79ef3
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
2 changes: 0 additions & 2 deletions builtin/common/async.lua → builtin/common/metatable.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
-- NOTE: This script is used by the main thread and async worker threads

-- Registered metatables, used in C++ for deserialization
local known_metatables = {}
function core.register_async_metatable(name, mt)
Expand Down
2 changes: 1 addition & 1 deletion builtin/game/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ if core.settings:get_bool("profiler.load") then
end

dofile(commonpath .. "after.lua")
dofile(commonpath .. "async.lua")
dofile(commonpath .. "metatable.lua")
dofile(commonpath .. "mod_storage.lua")
dofile(gamepath .. "item_entity.lua")
dofile(gamepath .. "deprecated.lua")
Expand Down
3 changes: 1 addition & 2 deletions builtin/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,9 @@ elseif INIT == "mainmenu" then
dofile(core.get_mainmenu_path() .. DIR_DELIM .. "init.lua")
end
elseif INIT == "async" then
dofile(commonpath .. "async.lua")
dofile(asyncpath .. "mainmenu.lua")
elseif INIT == "async_game" then
dofile(commonpath .. "async.lua")
dofile(commonpath .. "metatable.lua")
dofile(asyncpath .. "game.lua")
elseif INIT == "client" then
dofile(scriptdir .. "client" .. DIR_DELIM .. "init.lua")
Expand Down
13 changes: 8 additions & 5 deletions src/script/common/c_packer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,7 @@ static inline bool get_known_lua_metatables(lua_State *L)
}
lua_getfield(L, -1, "known_metatables");
if (lua_istable(L, -1)) {
lua_insert(L, -2);
lua_pop(L, 1);
lua_remove(L, -2);
return true;
}
lua_pop(L, 2);
Expand Down Expand Up @@ -479,6 +478,7 @@ static VectorRef<PackedInstr> pack_inner(lua_State *L, int idx, int vidx, Packed
if (lua_isstring(L, -1)) {
auto r = emplace(pv, INSTR_SETMETATABLE);
r->sdata = std::string(lua_tostring(L, -1));
r->set_into = vi_table;
}
lua_pop(L, 2);
}
Expand Down Expand Up @@ -550,13 +550,13 @@ void script_unpack(lua_State *L, PackedValue *pv)
case INSTR_SETMETATABLE:
if (get_known_lua_metatables(L)) {
lua_getfield(L, -1, i.sdata.c_str());
lua_remove(L, -2);
if (lua_istable(L, -1))
lua_setmetatable(L, -3);
lua_setmetatable(L, top+i.set_into);
else
lua_pop(L, 1);
lua_pop(L, 1);
}
break;
continue;

/* Lua types */
case LUA_TNIL:
Expand Down Expand Up @@ -657,6 +657,9 @@ void script_dump_packed(const PackedValue *val)
case INSTR_PUSHREF:
printf("PUSHREF(%d)", i.sidata1);
break;
case INSTR_SETMETATABLE:
printf("SETMETATABLE(%d, %s)", i.set_into, i.sdata.c_str());
break;
case LUA_TNIL:
printf("nil");
break;
Expand Down

0 comments on commit fb79ef3

Please sign in to comment.