mirror of
https://github.com/luanti-org/luanti.git
synced 2025-06-27 16:36:03 +00:00
SAPI: Track last executed mod and include in error messages
This commit is contained in:
parent
738fbc66d0
commit
2b04ab874d
19 changed files with 231 additions and 45 deletions
|
@ -438,6 +438,31 @@ int ModApiServer::l_notify_authentication_modified(lua_State *L)
|
|||
return 0;
|
||||
}
|
||||
|
||||
// get_last_run_mod()
|
||||
int ModApiServer::l_get_last_run_mod(lua_State *L)
|
||||
{
|
||||
NO_MAP_LOCK_REQUIRED;
|
||||
lua_getfield(L, LUA_REGISTRYINDEX, SCRIPT_MOD_NAME_FIELD);
|
||||
const char *current_mod = lua_tostring(L, -1);
|
||||
if (current_mod == NULL || current_mod[0] == '\0') {
|
||||
lua_pop(L, 1);
|
||||
lua_pushstring(L, getScriptApiBase(L)->getOrigin().c_str());
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
// set_last_run_mod(modname)
|
||||
int ModApiServer::l_set_last_run_mod(lua_State *L)
|
||||
{
|
||||
NO_MAP_LOCK_REQUIRED;
|
||||
#ifdef SCRIPTAPI_DEBUG
|
||||
const char *mod = lua_tostring(L, 1);
|
||||
getScriptApiBase(L)->setOriginDirect(mod);
|
||||
//printf(">>>> last mod set from Lua: %s\n", mod);
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifndef NDEBUG
|
||||
// cause_error(type_of_error)
|
||||
int ModApiServer::l_cause_error(lua_State *L)
|
||||
|
@ -495,6 +520,8 @@ void ModApiServer::Initialize(lua_State *L, int top)
|
|||
API_FCT(unban_player_or_ip);
|
||||
API_FCT(notify_authentication_modified);
|
||||
|
||||
API_FCT(get_last_run_mod);
|
||||
API_FCT(set_last_run_mod);
|
||||
#ifndef NDEBUG
|
||||
API_FCT(cause_error);
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue