diff options
author | sfan5 <sfan5@live.de> | 2021-12-18 20:36:43 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-12-18 20:36:43 +0100 |
commit | 8472141b79c25092c90dea24aa873bd7ff792142 (patch) | |
tree | f83851a66ec4b892786ae8a398bee3e8c5228c78 /src | |
parent | 1c5ece8334d050379eb99fe2ead52f9f4db44249 (diff) | |
download | minetest-8472141b79c25092c90dea24aa873bd7ff792142.tar.gz minetest-8472141b79c25092c90dea24aa873bd7ff792142.tar.bz2 minetest-8472141b79c25092c90dea24aa873bd7ff792142.zip |
Restructure devtest's unittests and run them in CI (#11859)
Diffstat (limited to 'src')
-rw-r--r-- | src/script/cpp_api/s_base.h | 9 | ||||
-rw-r--r-- | src/script/cpp_api/s_server.cpp | 6 | ||||
-rw-r--r-- | src/script/cpp_api/s_server.h | 2 | ||||
-rw-r--r-- | src/script/lua_api/l_server.cpp | 2 |
4 files changed, 13 insertions, 6 deletions
diff --git a/src/script/cpp_api/s_base.h b/src/script/cpp_api/s_base.h index 06df2abe3..244d81605 100644 --- a/src/script/cpp_api/s_base.h +++ b/src/script/cpp_api/s_base.h @@ -125,6 +125,15 @@ protected: friend class ModApiEnvMod; friend class LuaVoxelManip; + /* + Subtle edge case with coroutines: If for whatever reason you have a + method in a subclass that's called from existing lua_CFunction + (any of the l_*.cpp files) then make it static and take the lua_State* + as an argument. This is REQUIRED because getStack() will not return the + correct state if called inside coroutines. + + Also note that src/script/common/ is the better place for such helpers. + */ lua_State* getStack() { return m_luastack; } diff --git a/src/script/cpp_api/s_server.cpp b/src/script/cpp_api/s_server.cpp index 6ddb2630d..c255b0c71 100644 --- a/src/script/cpp_api/s_server.cpp +++ b/src/script/cpp_api/s_server.cpp @@ -198,10 +198,8 @@ std::string ScriptApiServer::formatChatMessage(const std::string &name, return ret; } -u32 ScriptApiServer::allocateDynamicMediaCallback(int f_idx) +u32 ScriptApiServer::allocateDynamicMediaCallback(lua_State *L, int f_idx) { - lua_State *L = getStack(); - if (f_idx < 0) f_idx = lua_gettop(L) + f_idx + 1; @@ -235,7 +233,7 @@ u32 ScriptApiServer::allocateDynamicMediaCallback(int f_idx) void ScriptApiServer::freeDynamicMediaCallback(u32 token) { - lua_State *L = getStack(); + SCRIPTAPI_PRECHECKHEADER verbosestream << "freeDynamicMediaCallback(" << token << ")" << std::endl; diff --git a/src/script/cpp_api/s_server.h b/src/script/cpp_api/s_server.h index c5c3d5596..58c8c0e48 100644 --- a/src/script/cpp_api/s_server.h +++ b/src/script/cpp_api/s_server.h @@ -51,7 +51,7 @@ public: const std::string &password); /* dynamic media handling */ - u32 allocateDynamicMediaCallback(int f_idx); + static u32 allocateDynamicMediaCallback(lua_State *L, int f_idx); void freeDynamicMediaCallback(u32 token); void on_dynamic_media_added(u32 token, const char *playername); diff --git a/src/script/lua_api/l_server.cpp b/src/script/lua_api/l_server.cpp index 82a692070..88ab5e16b 100644 --- a/src/script/lua_api/l_server.cpp +++ b/src/script/lua_api/l_server.cpp @@ -496,7 +496,7 @@ int ModApiServer::l_dynamic_add_media(lua_State *L) CHECK_SECURE_PATH(L, filepath.c_str(), false); - u32 token = server->getScriptIface()->allocateDynamicMediaCallback(2); + u32 token = server->getScriptIface()->allocateDynamicMediaCallback(L, 2); bool ok = server->dynamicAddMedia(filepath, token, to_player, ephemeral); if (!ok) |