diff options
Diffstat (limited to 'src/Bindings/ManualBindings_World.cpp')
-rw-r--r-- | src/Bindings/ManualBindings_World.cpp | 45 |
1 files changed, 16 insertions, 29 deletions
diff --git a/src/Bindings/ManualBindings_World.cpp b/src/Bindings/ManualBindings_World.cpp index 7bf4d3f80..88e3917da 100644 --- a/src/Bindings/ManualBindings_World.cpp +++ b/src/Bindings/ManualBindings_World.cpp @@ -413,48 +413,35 @@ static int tolua_cWorld_PrepareChunk(lua_State * tolua_S) return 0; } - // Read the params: - cWorld * world = nullptr; - int chunkX = 0; - int chunkZ = 0; - L.GetStackValues(1, world, chunkX, chunkZ); - if (world == nullptr) - { - LOGWARNING("World:PrepareChunk(): invalid world parameter"); - L.LogStackTrace(); - return 0; - } - // Wrap the Lua callback inside a C++ callback class: class cCallback: public cChunkCoordCallback { public: - cCallback(lua_State * a_LuaState): - m_LuaState(a_LuaState), - m_Callback(m_LuaState, 4) - { - } - // cChunkCoordCallback override: virtual void Call(int a_CBChunkX, int a_CBChunkZ, bool a_IsSuccess) override { - if (m_Callback.IsValid()) - { - m_LuaState.Call(m_Callback, a_CBChunkX, a_CBChunkZ, a_IsSuccess); - } - - // This is the last reference of this object, we must delete it so that it doesn't leak: - delete this; + m_LuaCallback.Call(a_CBChunkX, a_CBChunkZ, a_IsSuccess); } - protected: - cLuaState m_LuaState; - cLuaState::cRef m_Callback; + cLuaState::cOptionalCallback m_LuaCallback; }; + // Read the params: + cWorld * world = nullptr; + int chunkX = 0; + int chunkZ = 0; + auto Callback = cpp14::make_unique<cCallback>(); + L.GetStackValues(1, world, chunkX, chunkZ, Callback->m_LuaCallback); + if (world == nullptr) + { + LOGWARNING("World:PrepareChunk(): invalid world parameter"); + L.LogStackTrace(); + return 0; + } + // Call the chunk preparation: - world->PrepareChunk(chunkX, chunkZ, cpp14::make_unique<cCallback>(tolua_S)); + world->PrepareChunk(chunkX, chunkZ, std::move(Callback)); return 0; } |