mirror of
https://github.com/luanti-org/luanti.git
synced 2025-08-01 17:38:41 +00:00
some error handling stuff
This commit is contained in:
parent
ce39f41cef
commit
b3cd495936
7 changed files with 47 additions and 14 deletions
|
@ -17,8 +17,7 @@ void ScriptApiSSCSM::load_mods(const std::vector<std::string> &init_paths)
|
|||
actionstream << " " << p << ":\n";
|
||||
auto f = env->readVFSFile(p);
|
||||
if (!f.has_value()) {
|
||||
env->setFatalError("load_mods(): File doesn't exist: " + p);
|
||||
return;
|
||||
throw ModError("load_mods(): File doesn't exist: " + p);
|
||||
}
|
||||
actionstream << *f << "\n";
|
||||
}
|
||||
|
@ -33,9 +32,5 @@ void ScriptApiSSCSM::environment_step(float dtime)
|
|||
lua_getfield(L, -1, "registered_globalsteps");
|
||||
// Call callbacks
|
||||
lua_pushnumber(L, dtime);
|
||||
try {
|
||||
runCallbacks(1, RUN_CALLBACKS_MODE_FIRST);
|
||||
} catch (LuaError &e) {
|
||||
getSSCSMEnv()->setFatalError(e);
|
||||
}
|
||||
runCallbacks(1, RUN_CALLBACKS_MODE_FIRST);
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
#include "mapnode.h"
|
||||
|
||||
// print(text)
|
||||
int ModApiSSCSM::l_print(lua_State *L)
|
||||
int ModApiSSCSM::l_print(lua_State *L) //TODO: not core.print
|
||||
{
|
||||
auto request = SSCSMRequestPrint{};
|
||||
request.text = luaL_checkstring(L, 1);
|
||||
|
@ -22,6 +22,37 @@ int ModApiSSCSM::l_print(lua_State *L)
|
|||
return 0;
|
||||
}
|
||||
|
||||
// log([level], text)
|
||||
int ModApiSSCSM::l_log(lua_State *L)
|
||||
{
|
||||
/*
|
||||
auto request = SSCSMRequestLog{};
|
||||
request.text = luaL_checkstring(L, 1);
|
||||
getSSCSMEnv(L)->doRequest(std::move(request));
|
||||
|
||||
std::string_view text;
|
||||
LogLevel level = LL_NONE;
|
||||
if (lua_isnoneornil(L, 2)) {
|
||||
text = readParam<std::string_view>(L, 1);
|
||||
} else {
|
||||
auto name = readParam<std::string_view>(L, 1);
|
||||
text = readParam<std::string_view>(L, 2);
|
||||
// if (name == "deprecated") { //TODO
|
||||
// log_deprecated(L, text, 2);
|
||||
// return 0;
|
||||
// }
|
||||
level = Logger::stringToLevel(name);
|
||||
if (level == LL_MAX) {
|
||||
warningstream << "Tried to log at unknown level '" << name
|
||||
<< "'. Defaulting to \"none\"." << std::endl;
|
||||
level = LL_WARNING;
|
||||
}
|
||||
}
|
||||
g_logger.log(level, text);
|
||||
*/
|
||||
return 0;
|
||||
}
|
||||
|
||||
// get_node_or_nil(pos)
|
||||
// pos = {x=num, y=num, z=num}
|
||||
int ModApiSSCSM::l_get_node_or_nil(lua_State *L)
|
||||
|
@ -46,5 +77,6 @@ int ModApiSSCSM::l_get_node_or_nil(lua_State *L)
|
|||
void ModApiSSCSM::Initialize(lua_State *L, int top)
|
||||
{
|
||||
API_FCT(print);
|
||||
API_FCT(log);
|
||||
API_FCT(get_node_or_nil);
|
||||
}
|
||||
|
|
|
@ -12,6 +12,9 @@ private:
|
|||
// print(text)
|
||||
static int l_print(lua_State *L);
|
||||
|
||||
// log([level], text)
|
||||
static int l_log(lua_State *L);
|
||||
|
||||
// get_node_or_nil(pos)
|
||||
static int l_get_node_or_nil(lua_State *L);
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
// #include "lua_api/l_util.h"
|
||||
|
||||
SSCSMScripting::SSCSMScripting(SSCSMEnvironment *env) :
|
||||
ScriptApiBase(ScriptingType::SSCSM)
|
||||
ScriptApiBase(ScriptingType::SSCSM) //TODO: use different CUSTOM_RIDX_ERROR_HANDLER, or set debug.traceback
|
||||
{
|
||||
setSSCSMEnv(env);
|
||||
|
||||
|
|
|
@ -24,7 +24,13 @@ void *SSCSMEnvironment::run()
|
|||
break;
|
||||
}
|
||||
|
||||
next_event->exec(this);
|
||||
try {
|
||||
next_event->exec(this);
|
||||
} catch (LuaError &e) {
|
||||
setFatalError(std::string("Lua error: ") + e.what());
|
||||
} catch (ModError &e) {
|
||||
setFatalError(std::string("Mod error: ") + e.what());
|
||||
}
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
|
|
|
@ -40,10 +40,6 @@ public:
|
|||
std::optional<std::string_view> readVFSFile(const std::string &path);
|
||||
|
||||
void setFatalError(const std::string &reason);
|
||||
void setFatalError(const LuaError &e)
|
||||
{
|
||||
setFatalError(std::string("Lua: ") + e.what());
|
||||
}
|
||||
|
||||
template <typename RQ>
|
||||
typename RQ::Answer doRequest(RQ &&rq)
|
||||
|
|
|
@ -60,6 +60,7 @@ struct SSCSMRequestPrint : public ISSCSMRequest
|
|||
};
|
||||
|
||||
// core.log(level, text)
|
||||
// FIXME: override global loggers to use this in sscsm process
|
||||
struct SSCSMRequestLog : public ISSCSMRequest
|
||||
{
|
||||
struct Answer : public ISSCSMAnswer
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue