aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--builtin/async/game.lua3
-rw-r--r--builtin/game/misc.lua2
-rw-r--r--src/script/common/c_packer.h2
-rw-r--r--src/script/scripting_server.cpp9
-rw-r--r--src/server.cpp1
-rw-r--r--src/server.h5
6 files changed, 11 insertions, 11 deletions
diff --git a/builtin/async/game.lua b/builtin/async/game.lua
index 212a33e17..8cb9720b6 100644
--- a/builtin/async/game.lua
+++ b/builtin/async/game.lua
@@ -22,8 +22,7 @@ dofile(gamepath .. "voxelarea.lua")
-- Transfer of globals
do
- assert(core.transferred_globals)
- local all = core.deserialize(core.transferred_globals, true)
+ local all = assert(core.transferred_globals)
core.transferred_globals = nil
-- reassemble other tables
diff --git a/builtin/game/misc.lua b/builtin/game/misc.lua
index 9f5e3312b..997b1894a 100644
--- a/builtin/game/misc.lua
+++ b/builtin/game/misc.lua
@@ -262,5 +262,5 @@ function core.get_globals_to_transfer()
registered_items = copy_filtering(core.registered_items),
registered_aliases = core.registered_aliases,
}
- return core.serialize(all)
+ return all
end
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'
}
diff --git a/src/server.cpp b/src/server.cpp
index ebe1d1f6b..d93f300d2 100644
--- a/src/server.cpp
+++ b/src/server.cpp
@@ -243,7 +243,6 @@ Server::Server(
m_clients(m_con),
m_admin_chat(iface),
m_on_shutdown_errmsg(on_shutdown_errmsg),
- m_async_globals_data(""),
m_modchannel_mgr(new ModChannelMgr())
{
if (m_path_world.empty())
diff --git a/src/server.h b/src/server.h
index ecba30b95..2c21f5dfc 100644
--- a/src/server.h
+++ b/src/server.h
@@ -73,6 +73,7 @@ struct Lighting;
class ServerThread;
class ServerModManager;
class ServerInventoryManager;
+struct PackedValue;
enum ClientDeletionReason {
CDR_LEAVE,
@@ -388,8 +389,8 @@ public:
// Lua files registered for init of async env, pair of modname + path
std::vector<std::pair<std::string, std::string>> m_async_init_files;
- // Serialized data transferred into async envs at init time
- MutexedVariable<std::string> m_async_globals_data;
+ // Data transferred into async envs at init time
+ std::unique_ptr<PackedValue> m_async_globals_data;
// Bind address
Address m_bind_addr;