From: Perttu Ahola Date: Mon, 2 Jan 2012 14:26:40 +0000 (+0200) Subject: Add name field to registered entities X-Git-Url: http://81.2.79.47:8989/gitweb/?a=commitdiff_plain;h=ab57fbe4caa5a8d74ec08c7a7f3d2cb04faf9de0;p=zefram%2Fminetest%2Fminetest_engine.git Add name field to registered entities --- diff --git a/data/mods/default/init.lua b/data/mods/default/init.lua index ac3ef1b8..073483d4 100644 --- a/data/mods/default/init.lua +++ b/data/mods/default/init.lua @@ -239,6 +239,7 @@ -- -- Registered entities: -- - Functions receive a "luaentity" as self: +-- - It has the member .name, which is the registered name ("mod:thing") -- - It has the member .object, which is an ObjectRef pointing to the object -- - The original prototype stuff is visible directly via a metatable -- - Callbacks: diff --git a/src/scriptapi.cpp b/src/scriptapi.cpp index 401de8ad..dbbaf3dc 100644 --- a/src/scriptapi.cpp +++ b/src/scriptapi.cpp @@ -2652,6 +2652,10 @@ static int l_register_entity(lua_State *L) // Get registered object to top of stack lua_pushvalue(L, 2); + + // Set name field + lua_pushvalue(L, 1); + lua_setfield(L, -2, "name"); // Set __index to point to itself lua_pushvalue(L, -1);