diff --git a/src/Lib/Script/LuaContext.cc b/src/Lib/Script/LuaContext.cc index 818878321b90c2a63985f86f65b8c92473db0d65..a7c26e659ec30d9e216967d501df263b5c84c285 100644 --- a/src/Lib/Script/LuaContext.cc +++ b/src/Lib/Script/LuaContext.cc @@ -201,8 +201,11 @@ LuaContext::getModule(const std::string_view name) const noexcept const int r = modules.at(name); lua_rawgeti(L, LUA_REGISTRYINDEX, r); return ModuleDeclaration::CHECK(L, -1); - } else { - lua_pushnil(L); + } + + else { + const std::string moduleName(name); + luaL_error(L, "Module %s not found", moduleName.c_str()); return nullptr; } } @@ -214,8 +217,12 @@ LuaContext::getFunction(const std::string_view module, const std::string_view na const int r = functions.at({ module, name }); lua_rawgeti(L, LUA_REGISTRYINDEX, r); return FunctionDeclaration::CHECK(L, -1); - } else { - lua_pushnil(L); + } + + else { + const std::string moduleName(module); + const std::string functionName(name); + luaL_error(L, "Function %s::%s not found", moduleName.c_str(), functionName.c_str()); return nullptr; } } @@ -223,13 +230,17 @@ LuaContext::getFunction(const std::string_view module, const std::string_view na JobDeclaration * LuaContext::getJob(const std::string_view module, const std::string_view name) const noexcept { - if (moduleExists(module)) { + if (moduleExists(module) && jobs.count({ module, name }) >= 1) { const int r = jobs.at({ module, name }); lua_rawgeti(L, LUA_REGISTRYINDEX, r); return JobDeclaration::CHECK(L, -1); - } else { - lua_pushnil(L); - return nullptr; + } + + else { + const std::string moduleName(module); + const std::string jobName(name); + luaL_error(L, "Job %s::%s not found", moduleName.c_str(), jobName.c_str()); + return nullptr; // Unreachable } }