aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPerttu Ahola <celeron55@gmail.com>2012-01-02 12:48:25 +0200
committerPerttu Ahola <celeron55@gmail.com>2012-01-02 12:48:25 +0200
commit49b7055cb3f676c19dc5edd07fe72e2f5e2414a1 (patch)
tree45dbd52a817425dae864273f217316d5a929e96e /src
parentcb88f7b6d4c863e9ae986df14a457dc8355830cb (diff)
downloadminetest-49b7055cb3f676c19dc5edd07fe72e2f5e2414a1.tar.gz
minetest-49b7055cb3f676c19dc5edd07fe72e2f5e2414a1.tar.bz2
minetest-49b7055cb3f676c19dc5edd07fe72e2f5e2414a1.zip
Make add_entity return a reference to added entity (or nil)
Diffstat (limited to 'src')
-rw-r--r--src/scriptapi.cpp9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/scriptapi.cpp b/src/scriptapi.cpp
index 4dcb66c77..6b850b19a 100644
--- a/src/scriptapi.cpp
+++ b/src/scriptapi.cpp
@@ -2352,8 +2352,13 @@ private:
const char *name = luaL_checkstring(L, 3);
// Do it
ServerActiveObject *obj = new LuaEntitySAO(env, pos, name, "");
- env->addActiveObject(obj);
- return 0;
+ int objectid = env->addActiveObject(obj);
+ // If failed to add, return nothing (reads as nil)
+ if(objectid == 0)
+ return 0;
+ // Return ObjectRef
+ objectref_get_or_create(L, obj);
+ return 1;
}
// EnvRef:add_item(pos, inventorystring)