diff options
author | sfan5 <sfan5@live.de> | 2022-05-09 18:20:10 +0200 |
---|---|---|
committer | sfan5 <sfan5@live.de> | 2022-05-10 22:37:42 +0200 |
commit | ec9f1575121e3b064b919bca7efddfa8b0fc4e65 (patch) | |
tree | 54d87ba45143f9d8d64e3ee3b8c36f6296627bdc /src/script | |
parent | 7f58887ae33893c981fbdff23d4e1fa4a11c32e4 (diff) | |
download | minetest-ec9f1575121e3b064b919bca7efddfa8b0fc4e65.tar.gz minetest-ec9f1575121e3b064b919bca7efddfa8b0fc4e65.tar.bz2 minetest-ec9f1575121e3b064b919bca7efddfa8b0fc4e65.zip |
Use native packer to transfer globals into async env(s)
Diffstat (limited to 'src/script')
-rw-r--r-- | src/script/common/c_packer.h | 2 | ||||
-rw-r--r-- | src/script/scripting_server.cpp | 9 |
2 files changed, 6 insertions, 5 deletions
diff --git a/src/script/common/c_packer.h b/src/script/common/c_packer.h index ee732be86..fe072c10a 100644 --- a/src/script/common/c_packer.h +++ b/src/script/common/c_packer.h @@ -119,7 +119,7 @@ void script_register_packer(lua_State *L, const char *regname, // Pack a Lua value PackedValue *script_pack(lua_State *L, int idx); // Unpack a Lua value (left on top of stack) -// Note that this may modify the PackedValue, you can't reuse it! +// Note that this may modify the PackedValue, reusability is not guaranteed! void script_unpack(lua_State *L, PackedValue *val); // Dump contents of PackedValue to stdout for debugging diff --git a/src/script/scripting_server.cpp b/src/script/scripting_server.cpp index 5b99468dc..b462141b0 100644 --- a/src/script/scripting_server.cpp +++ b/src/script/scripting_server.cpp @@ -98,8 +98,9 @@ void ServerScripting::initAsync() luaL_checktype(L, -1, LUA_TTABLE); lua_getfield(L, -1, "get_globals_to_transfer"); lua_call(L, 0, 1); - luaL_checktype(L, -1, LUA_TSTRING); - getServer()->m_async_globals_data.set(readParam<std::string>(L, -1)); + auto *data = script_pack(L, -1); + assert(!data->contains_userdata); + getServer()->m_async_globals_data.reset(data); lua_pushnil(L); lua_setfield(L, -3, "get_globals_to_transfer"); // unset function too lua_pop(L, 2); // pop 'core', return value @@ -183,8 +184,8 @@ void ServerScripting::InitializeAsync(lua_State *L, int top) // globals data lua_getglobal(L, "core"); luaL_checktype(L, -1, LUA_TTABLE); - std::string s = ModApiBase::getServer(L)->m_async_globals_data.get(); - lua_pushlstring(L, s.c_str(), s.size()); + auto *data = ModApiBase::getServer(L)->m_async_globals_data.get(); + script_unpack(L, data); lua_setfield(L, -2, "transferred_globals"); lua_pop(L, 1); // pop 'core' } |