diff options
author | peterbell10 <peterbell10@live.co.uk> | 2017-07-12 11:56:01 +0200 |
---|---|---|
committer | Lukas Pioch <lukas@zgow.de> | 2017-07-12 11:56:01 +0200 |
commit | d6ee1caf4c405505abc239ca2f232c387625741e (patch) | |
tree | 4680f11b0f0352034106d34d192a385e009a10e6 /src/Bindings/ManualBindings_World.cpp | |
parent | Send player message when clicking on advancements or green book. (#3845) (diff) | |
download | cuberite-d6ee1caf4c405505abc239ca2f232c387625741e.tar cuberite-d6ee1caf4c405505abc239ca2f232c387625741e.tar.gz cuberite-d6ee1caf4c405505abc239ca2f232c387625741e.tar.bz2 cuberite-d6ee1caf4c405505abc239ca2f232c387625741e.tar.lz cuberite-d6ee1caf4c405505abc239ca2f232c387625741e.tar.xz cuberite-d6ee1caf4c405505abc239ca2f232c387625741e.tar.zst cuberite-d6ee1caf4c405505abc239ca2f232c387625741e.zip |
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; } |