#include "server.h"
#include "environment.h"
#include "player.h"
+#include "log.h"
// request_shutdown()
int ModApiServer::l_request_shutdown(lua_State *L)
int ModApiServer::l_get_current_modname(lua_State *L)
{
NO_MAP_LOCK_REQUIRED;
- lua_getfield(L, LUA_REGISTRYINDEX, "minetest_current_modname");
+ lua_getfield(L, LUA_REGISTRYINDEX, "current_modname");
return 1;
}
{
NO_MAP_LOCK_REQUIRED;
std::string modname = luaL_checkstring(L, 1);
- // Do it
- if(modname == "__builtin"){
- std::string path = getServer(L)->getBuiltinLuaPath();
- lua_pushstring(L, path.c_str());
- return 1;
- }
const ModSpec *mod = getServer(L)->getModSpec(modname);
- if(!mod){
+ if (!mod) {
lua_pushnil(L);
return 1;
}
NO_MAP_LOCK_REQUIRED;
// Get a list of mods
- std::list<std::string> mods_unsorted, mods_sorted;
+ std::vector<std::string> mods_unsorted;
+ std::list<std::string> mods_sorted;
getServer(L)->getModNames(mods_unsorted);
// Take unsorted items from mods_unsorted and sort them into
// mods_sorted; not great performance but the number of mods on a
// server will likely be small.
- for(std::list<std::string>::iterator i = mods_unsorted.begin();
+ for(std::vector<std::string>::iterator i = mods_unsorted.begin();
i != mods_unsorted.end(); ++i) {
bool added = false;
for(std::list<std::string>::iterator x = mods_sorted.begin();
return 0;
}
+#ifndef NDEBUG
+// cause_error(type_of_error)
+int ModApiServer::l_cause_error(lua_State *L)
+{
+ NO_MAP_LOCK_REQUIRED;
+ std::string type_of_error = "none";
+ if(lua_isstring(L, 1))
+ type_of_error = lua_tostring(L, 1);
+
+ errorstream << "Error handler test called, errortype=" << type_of_error << std::endl;
+
+ if(type_of_error == "segv") {
+ volatile int* some_pointer = 0;
+ errorstream << "Cause a sigsegv now: " << (*some_pointer) << std::endl;
+
+ } else if (type_of_error == "zerodivision") {
+
+ unsigned int some_number = porting::getTimeS();
+ unsigned int zerovalue = 0;
+ unsigned int result = some_number / zerovalue;
+ errorstream << "Well this shouldn't ever be shown: " << result << std::endl;
+
+ } else if (type_of_error == "exception") {
+ throw BaseException("Errorhandler test fct called");
+ }
+
+ return 0;
+}
+#endif
+
void ModApiServer::Initialize(lua_State *L, int top)
{
API_FCT(request_shutdown);
API_FCT(kick_player);
API_FCT(unban_player_or_ip);
API_FCT(notify_authentication_modified);
+
+#ifndef NDEBUG
+ API_FCT(cause_error);
+#endif
}