diff --git a/Source/Integration/LuaCall.cpp b/Source/Integration/LuaCall.cpp index 7b1091bb..8d47dfff 100644 --- a/Source/Integration/LuaCall.cpp +++ b/Source/Integration/LuaCall.cpp @@ -205,25 +205,21 @@ FString UlxLuaCallLibrary::AllFunctionsWithPrefix(const TCHAR *Prefix) void UlxLuaCallLibrary::ValidateLuaExpr( ElxLuaSyntaxCheck &Status, FString &ErrorMessage, UObject *context, const FString &Code) { - if (Code.StartsWith(TEXT("/"))) - { - ErrorMessage = "SlashCommand"; - Status = ElxLuaSyntaxCheck::SlashCommand; - return; - } - if (Code.TrimStart().IsEmpty()) - { - ErrorMessage = ""; - Status = ElxLuaSyntaxCheck::Whitespace; - return; - } ALuprexGameModeBase *mode = ALuprexGameModeBase::FromContext(context); ErrorMessage = mode->ValidateLuaExpr(Code); if (ErrorMessage.IsEmpty()) { Status = ElxLuaSyntaxCheck::ValidLua; } - else if (ErrorMessage.Contains(TEXT(""))) + else if (ErrorMessage == TEXT("slash command")) + { + Status = ElxLuaSyntaxCheck::SlashCommand; + } + else if (ErrorMessage == TEXT("white space")) + { + Status = ElxLuaSyntaxCheck::Whitespace; + } + else if (ErrorMessage == TEXT("truncated lua")) { Status = ElxLuaSyntaxCheck::TruncatedLua; } diff --git a/luprex/cpp/core/luastack.cpp b/luprex/cpp/core/luastack.cpp index fc8b7331..83868410 100644 --- a/luprex/cpp/core/luastack.cpp +++ b/luprex/cpp/core/luastack.cpp @@ -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 ")) + { + message = "truncated lua"; + } if (message.empty()) message = "unknown compiler error"; set(result, message); return message; diff --git a/luprex/cpp/core/util.cpp b/luprex/cpp/core/util.cpp index f489a6a7..c1098f5a 100644 --- a/luprex/cpp/core/util.cpp +++ b/luprex/cpp/core/util.cpp @@ -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; diff --git a/luprex/cpp/core/util.hpp b/luprex/cpp/core/util.hpp index 66ce05e2..abb7551d 100644 --- a/luprex/cpp/core/util.hpp +++ b/luprex/cpp/core/util.hpp @@ -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) {