]> git.lizzy.rs Git - minetest.git/commitdiff
Fix entity related bugs
authorsfan5 <sfan5@live.de>
Tue, 14 Jun 2022 10:39:01 +0000 (12:39 +0200)
committersfan5 <sfan5@live.de>
Wed, 15 Jun 2022 15:20:07 +0000 (17:20 +0200)
* Make minetest.add_entity() binary-safe
* Fix on_death pushing dummy ObjectRef instead of nil

src/script/cpp_api/s_entity.cpp
src/script/lua_api/l_env.cpp

index 9368bec760385f722edc891baa77217c72dc2a1f..852a27ddcfe3efd03e02d20cb07c40ff0b89cb75 100644 (file)
@@ -244,7 +244,7 @@ bool ScriptApiEntity::luaentity_Punch(u16 id,
 {
        SCRIPTAPI_PRECHECKHEADER
 
-       //infostream<<"scriptapi_luaentity_step: id="<<id<<std::endl;
+       assert(puncher);
 
        int error_handler = PUSH_ERROR_HANDLER(L);
 
@@ -294,7 +294,10 @@ bool ScriptApiEntity::luaentity_run_simple_callback(u16 id,
        }
        luaL_checktype(L, -1, LUA_TFUNCTION);
        lua_pushvalue(L, object);  // self
-       objectrefGetOrCreate(L, sao);  // killer reference
+       if (sao)
+               objectrefGetOrCreate(L, sao);  // sao reference
+       else
+               lua_pushnil(L);
 
        setOriginFromTable(object);
        PCALL_RES(lua_pcall(L, 2, 1, error_handler));
index 7640f27825dde091016f9ca0a848676836e11326..ee49fd6bd3012c6aca118fbbbe37fd4233015ea8 100644 (file)
@@ -640,7 +640,7 @@ int ModApiEnvMod::l_add_entity(lua_State *L)
 
        v3f pos = checkFloatPos(L, 1);
        const char *name = luaL_checkstring(L, 2);
-       const char *staticdata = luaL_optstring(L, 3, "");
+       std::string staticdata = readParam<std::string>(L, 3, "");
 
        ServerActiveObject *obj = new LuaEntitySAO(env, pos, name, staticdata);
        int objectid = env->addActiveObject(obj);