Make LuaStack::Load return special codes for 'slash command', 'white space', and 'truncated lua'
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -199,6 +199,15 @@ bool is_lua_comment(string_view s) {
|
||||
return s.substr(start, 2) == "--";
|
||||
}
|
||||
|
||||
bool is_whitespace(string_view s) {
|
||||
for (int i = 0; i < int(s.size()); i++) {
|
||||
if (!ascii_isspace(s[i])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
string_view read_to_sep(string_view &source, char sep) {
|
||||
size_t pos = source.find(sep);
|
||||
string_view result;
|
||||
|
||||
@@ -110,6 +110,9 @@ bool is_lua_classname(string_view s);
|
||||
// Return true if the line of code is a lua comment.
|
||||
bool is_lua_comment(string_view s);
|
||||
|
||||
// Return true if the line is entirely whitespace.
|
||||
bool is_whitespace(string_view s);
|
||||
|
||||
// Return the first character, but if the view is empty,
|
||||
// return zero.
|
||||
inline char zfront(string_view &s) {
|
||||
|
||||
Reference in New Issue
Block a user