Make LuaStack::Load return special codes for 'slash command', 'white space', and 'truncated lua'

This commit is contained in:
2025-12-18 14:45:57 -05:00
parent f75ff36c3d
commit 63aa5b4c15
4 changed files with 36 additions and 13 deletions

View File

@@ -333,6 +333,17 @@ eng::string LuaCoreStack::load(LuaSlot result, std::string_view code, std::strin
code = expanded;
}
if (sv::has_prefix(code, "/"))
{
set(result, "slash command");
return "slash command";
}
if (sv::is_whitespace(code))
{
set(result, "white space");
return "white space";
}
eng::string fullcontext = eng::string("=") + eng::string(context);
luaL_loadbuffer(L_, code.data(), code.size(), fullcontext.c_str());
int type = lua_type(L_, -1);
@@ -346,6 +357,10 @@ eng::string LuaCoreStack::load(LuaSlot result, std::string_view code, std::strin
const char *str = lua_tolstring(L_, -1, &len);
eng::string message(str, len);
lua_pop(L_, 1);
if (sv::has_suffix(message, "near <eof>"))
{
message = "truncated lua";
}
if (message.empty()) message = "unknown compiler error";
set(result, message);
return message;