From e8286e8894cf132eeda4bac9924e5fd8c74a7eb2 Mon Sep 17 00:00:00 2001 From: DTA7 Date: Thu, 21 Sep 2017 21:52:52 +0200 Subject: Set placer to nil instead of a non-functional one in item_OnPlace (#6449) * Set placer to nil instead of a non-functional one This requires nil checks in core.rotate_node and core.rotate_and_place. --- src/script/cpp_api/s_item.cpp | 7 ++++++- src/script/lua_api/l_env.cpp | 5 ++--- 2 files changed, 8 insertions(+), 4 deletions(-) (limited to 'src/script') diff --git a/src/script/cpp_api/s_item.cpp b/src/script/cpp_api/s_item.cpp index 032018f2f..e13da1c86 100644 --- a/src/script/cpp_api/s_item.cpp +++ b/src/script/cpp_api/s_item.cpp @@ -69,7 +69,12 @@ bool ScriptApiItem::item_OnPlace(ItemStack &item, // Call function LuaItemStack::create(L, item); - objectrefGetOrCreate(L, placer); + + if (!placer) + lua_pushnil(L); + else + objectrefGetOrCreate(L, placer); + pushPointedThing(pointed); PCALL_RES(lua_pcall(L, 3, 1, error_handler)); if (!lua_isnil(L, -1)) { diff --git a/src/script/lua_api/l_env.cpp b/src/script/lua_api/l_env.cpp index 393c4ed5f..46745facd 100644 --- a/src/script/lua_api/l_env.cpp +++ b/src/script/lua_api/l_env.cpp @@ -291,9 +291,8 @@ int ModApiEnvMod::l_place_node(lua_State *L) pointed.type = POINTEDTHING_NODE; pointed.node_abovesurface = pos; pointed.node_undersurface = pos + v3s16(0,-1,0); - // Place it with a NULL placer (appears in Lua as a non-functional - // ObjectRef) - bool success = scriptIfaceItem->item_OnPlace(item, NULL, pointed); + // Place it with a NULL placer (appears in Lua as nil) + bool success = scriptIfaceItem->item_OnPlace(item, nullptr, pointed); lua_pushboolean(L, success); return 1; } -- cgit v1.2.3