mirror of
https://github.com/luanti-org/luanti.git
synced 2025-06-27 16:36:03 +00:00
Move core.get_connected_players() implementation to C++
Keeping the ObjectRefs around in a table isn't ideal and this allows
removing the somewhat nonsensical is_player_connected() added in 86ef7147
.
This commit is contained in:
parent
c657fb343f
commit
0b8d3f99a5
6 changed files with 27 additions and 17 deletions
|
@ -640,6 +640,23 @@ int ModApiEnvMod::l_add_item(lua_State *L)
|
|||
return 1;
|
||||
}
|
||||
|
||||
// get_connected_players()
|
||||
int ModApiEnvMod::l_get_connected_players(lua_State *L)
|
||||
{
|
||||
GET_ENV_PTR;
|
||||
|
||||
lua_createtable(L, env->getPlayerCount(), 0);
|
||||
u32 i = 0;
|
||||
for (RemotePlayer *player : env->getPlayers()) {
|
||||
PlayerSAO *sao = player->getPlayerSAO();
|
||||
if (sao) {
|
||||
getScriptApiBase(L)->objectrefGetOrCreate(L, sao);
|
||||
lua_rawseti(L, -2, ++i);
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
// get_player_by_name(name)
|
||||
int ModApiEnvMod::l_get_player_by_name(lua_State *L)
|
||||
{
|
||||
|
@ -647,7 +664,7 @@ int ModApiEnvMod::l_get_player_by_name(lua_State *L)
|
|||
|
||||
// Do it
|
||||
const char *name = luaL_checkstring(L, 1);
|
||||
RemotePlayer *player = dynamic_cast<RemotePlayer *>(env->getPlayer(name));
|
||||
RemotePlayer *player = env->getPlayer(name);
|
||||
if (player == NULL){
|
||||
lua_pushnil(L);
|
||||
return 1;
|
||||
|
@ -1319,6 +1336,7 @@ void ModApiEnvMod::Initialize(lua_State *L, int top)
|
|||
API_FCT(find_nodes_with_meta);
|
||||
API_FCT(get_meta);
|
||||
API_FCT(get_node_timer);
|
||||
API_FCT(get_connected_players);
|
||||
API_FCT(get_player_by_name);
|
||||
API_FCT(get_objects_inside_radius);
|
||||
API_FCT(set_timeofday);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue