Add ObjRef:is_player() and modify ObjRef:get_player_name() to always return a string...
authorPerttu Ahola <celeron55@gmail.com>
Sat, 2 Jun 2012 12:47:36 +0000 (15:47 +0300)
committerPerttu Ahola <celeron55@gmail.com>
Sun, 3 Jun 2012 19:31:01 +0000 (22:31 +0300)
builtin/misc.lua
doc/lua_api.txt
src/scriptapi.cpp

index b3b1ec6e835150d553668421f4eb37d86fb233f4..e018aff85ce2517194fc6d028737771efbf7fb09 100644 (file)
@@ -44,7 +44,7 @@ function minetest.get_connected_players()
        -- This could be optimized a bit, but leave that for later
        local list = {}
        for _, obj in pairs(minetest.env:get_objects_inside_radius({x=0,y=0,z=0}, 1000000)) do
-               if obj:get_player_name() then
+               if obj:is_player() then
                        table.insert(list, obj)
                end
        end
index 6de255c0d701d6c2d17694a6a3ec4b4faf323771..ddab47262254ae05a9c0caa5e626546c89c30594 100644 (file)
@@ -913,7 +913,8 @@ LuaEntitySAO-only: (no-op for other objects)
 - get_entity_name() (DEPRECATED: Will be removed in a future version)
 - get_luaentity()
 Player-only: (no-op for other objects)
-- get_player_name(): will return nil if is not a player
+- is_player(): true for players, false for others
+- get_player_name(): returns "" if is not a player
 - get_look_dir(): get camera direction as a unit vector
 - get_look_pitch(): pitch in radians
 - get_look_yaw(): yaw in radians (wraps around pretty randomly as of now)
index 320a45ff9f0d8d7d583e6b2e87a121042ffae8ed..9744aaa33509c0655122eae37b2fa7c12e561f32 100644 (file)
@@ -2683,6 +2683,15 @@ private:
        }
        
        /* Player-only */
+
+       // is_player(self)
+       static int l_is_player(lua_State *L)
+       {
+               ObjectRef *ref = checkobject(L, 1);
+               Player *player = getplayer(ref);
+               lua_pushboolean(L, (player != NULL));
+               return 1;
+       }
        
        // get_player_name(self)
        static int l_get_player_name(lua_State *L)
@@ -2690,7 +2699,7 @@ private:
                ObjectRef *ref = checkobject(L, 1);
                Player *player = getplayer(ref);
                if(player == NULL){
-                       lua_pushnil(L);
+                       lua_pushlstring(L, "", 0);
                        return 1;
                }
                // Do it