// request_shutdown()
int ModApiServer::l_request_shutdown(lua_State *L)
{
+ NO_MAP_LOCK_REQUIRED;
const char *msg = lua_tolstring(L, 1, NULL);
bool reconnect = lua_toboolean(L, 2);
getServer(L)->requestShutdown(msg ? msg : "", reconnect);
return 1;
}
+// print(text)
+int ModApiServer::l_print(lua_State *L)
+{
+ NO_MAP_LOCK_REQUIRED;
+ std::string text;
+ text = luaL_checkstring(L, 1);
+ getServer(L)->printToConsoleOnly(text);
+ return 0;
+}
+
// chat_send_all(text)
int ModApiServer::l_chat_send_all(lua_State *L)
{
}
catch(con::PeerNotFoundException) // unlikely
{
- dstream << __FUNCTION_NAME << ": peer was not found" << std::endl;
+ dstream << FUNCTION_NAME << ": peer was not found" << std::endl;
lua_pushnil(L); // error
return 1;
}
}
catch(con::PeerNotFoundException) // unlikely
{
- dstream << __FUNCTION_NAME << ": peer was not found" << std::endl;
+ dstream << FUNCTION_NAME << ": peer was not found" << std::endl;
lua_pushnil(L); // error
return 1;
}
#define ERET(code) \
if (!(code)) { \
- dstream << __FUNCTION_NAME << ": peer was not found" << std::endl; \
+ dstream << FUNCTION_NAME << ": peer was not found" << std::endl; \
lua_pushnil(L); /* error */ \
return 1; \
}
}
catch(con::PeerNotFoundException) // unlikely
{
- dstream << __FUNCTION_NAME << ": peer was not found" << std::endl;
+ dstream << FUNCTION_NAME << ": peer was not found" << std::endl;
lua_pushboolean(L, false); // error
return 1;
}
int ModApiServer::l_get_current_modname(lua_State *L)
{
NO_MAP_LOCK_REQUIRED;
- lua_getfield(L, LUA_REGISTRYINDEX, SCRIPT_MOD_NAME_FIELD);
+ lua_rawgeti(L, LUA_REGISTRYINDEX, CUSTOM_RIDX_CURRENT_MOD_NAME);
return 1;
}
return 0;
}
+// get_last_run_mod()
+int ModApiServer::l_get_last_run_mod(lua_State *L)
+{
+ NO_MAP_LOCK_REQUIRED;
+ lua_rawgeti(L, LUA_REGISTRYINDEX, CUSTOM_RIDX_CURRENT_MOD_NAME);
+ 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)
API_FCT(get_modpath);
API_FCT(get_modnames);
+ API_FCT(print);
+
API_FCT(chat_send_all);
API_FCT(chat_send_player);
API_FCT(show_formspec);
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