From fdbe8ca9c63ac9724662644476ae3d6d667810e4 Mon Sep 17 00:00:00 2001 From: MihailRis Date: Wed, 6 Nov 2024 20:18:57 +0300 Subject: [PATCH] move particles to gfx.particles --- res/content/base/scripts/world.lua | 2 +- src/logic/scripting/lua/lua_util.hpp | 17 +++++++++++++++++ src/logic/scripting/scripting_hud.cpp | 2 +- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/res/content/base/scripts/world.lua b/res/content/base/scripts/world.lua index 5719c4fb..62d111ae 100644 --- a/res/content/base/scripts/world.lua +++ b/res/content/base/scripts/world.lua @@ -1,5 +1,5 @@ function on_block_broken(id, x, y, z, playerid) - particles.emit({x+0.5, y+0.5, z+0.5}, 64, { + gfx.particles.emit({x+0.5, y+0.5, z+0.5}, 64, { lifetime=1.0, spawn_interval=0.0001, explosion={4, 4, 4}, diff --git a/src/logic/scripting/lua/lua_util.hpp b/src/logic/scripting/lua/lua_util.hpp index 138aa73c..f2b51c53 100644 --- a/src/logic/scripting/lua/lua_util.hpp +++ b/src/logic/scripting/lua/lua_util.hpp @@ -599,6 +599,23 @@ namespace lua { setglobal(L, name); } + inline void openlib( + lua::State* L, + const std::string& package, + const std::string& name, + const luaL_Reg* libfuncs + ) { + if (!hasglobal(L, package)) { + createtable(L, 0, 1); + setglobal(L, package); + } + getglobal(L, package); + createtable(L, 0, 0); + luaL_setfuncs(L, libfuncs, 0); + setfield(L, name); + pop(L); + } + inline const char* require_string_field( lua::State* L, const std::string& name, int idx=-1 ) { diff --git a/src/logic/scripting/scripting_hud.cpp b/src/logic/scripting/scripting_hud.cpp index 0d970e0d..87548c2e 100644 --- a/src/logic/scripting/scripting_hud.cpp +++ b/src/logic/scripting/scripting_hud.cpp @@ -24,7 +24,7 @@ void scripting::on_frontend_init(Hud* hud, WorldRenderer* renderer) { auto L = lua::get_main_state(); lua::openlib(L, "hud", hudlib); - lua::openlib(L, "particles", particleslib); + lua::openlib(L, "gfx", "particles", particleslib); if (lua::getglobal(L, "__vc_create_hud_rules")) { lua::call_nothrow(L, 0, 0);