mirror of
https://github.com/luanti-org/luanti.git
synced 2025-06-27 16:36:03 +00:00
Add ObjRef:is_player() and modify ObjRef:get_player_name() to always return a string to aid better inter-object compatibility of code that assumes objects to be players
This commit is contained in:
parent
b235e4d290
commit
bf8cfce50e
3 changed files with 13 additions and 3 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue