mirror of
https://github.com/luanti-org/luanti.git
synced 2025-10-14 09:05:19 +02:00
Revise dynamic_add_media API to better accomodate future changes
This commit is contained in:
@@ -452,19 +452,30 @@ int ModApiServer::l_sound_fade(lua_State *L)
|
||||
}
|
||||
|
||||
// dynamic_add_media(filepath)
|
||||
int ModApiServer::l_dynamic_add_media(lua_State *L)
|
||||
int ModApiServer::l_dynamic_add_media_raw(lua_State *L)
|
||||
{
|
||||
NO_MAP_LOCK_REQUIRED;
|
||||
|
||||
// Reject adding media before the server has started up
|
||||
if (!getEnv(L))
|
||||
throw LuaError("Dynamic media cannot be added before server has started up");
|
||||
|
||||
std::string filepath = readParam<std::string>(L, 1);
|
||||
CHECK_SECURE_PATH(L, filepath.c_str(), false);
|
||||
|
||||
bool ok = getServer(L)->dynamicAddMedia(filepath);
|
||||
lua_pushboolean(L, ok);
|
||||
std::vector<RemotePlayer*> sent_to;
|
||||
bool ok = getServer(L)->dynamicAddMedia(filepath, sent_to);
|
||||
if (ok) {
|
||||
// (see wrapper code in builtin)
|
||||
lua_createtable(L, sent_to.size(), 0);
|
||||
int i = 0;
|
||||
for (RemotePlayer *player : sent_to) {
|
||||
lua_pushstring(L, player->getName());
|
||||
lua_rawseti(L, -2, ++i);
|
||||
}
|
||||
} else {
|
||||
lua_pushboolean(L, false);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -532,7 +543,7 @@ void ModApiServer::Initialize(lua_State *L, int top)
|
||||
API_FCT(sound_play);
|
||||
API_FCT(sound_stop);
|
||||
API_FCT(sound_fade);
|
||||
API_FCT(dynamic_add_media);
|
||||
API_FCT(dynamic_add_media_raw);
|
||||
|
||||
API_FCT(get_player_information);
|
||||
API_FCT(get_player_privs);
|
||||
|
Reference in New Issue
Block a user