Add VALIDATE_LUA as a function in lpxserver and lpxclient

This commit is contained in:
2025-12-03 19:55:53 -05:00
parent 27b5ce7ef4
commit a242244f9c
9 changed files with 86 additions and 27 deletions

View File

@@ -89,26 +89,23 @@ void LuaConsole::add(eng::string line) {
}
// Try to parse the lua expression
int top = lua_gettop(lua_state_);
int status = luaL_loadbuffer(lua_state_, partial.c_str(), partial.size(), "=stdin");
if (status == LUA_ERRSYNTAX)
{
const char *eof = "<eof>";
int leof = strlen(eof);
size_t lmsg;
const char *msg = lua_tolstring(lua_state_, -1, &lmsg);
const char *tp = msg + lmsg - leof;
if (strstr(msg, eof) != tp) {
LuaVar result;
LuaDefStack LS(lua_state_, result);
eng::string errmsg = LS.load(result, partial, "stdin");
if (errmsg.empty()) {
words_.push_back(lua_mode);
words_.emplace_back(sv::rtrim(partial));
clear_raw_input();
} else if (errmsg.find("<eof>") != std::string::npos) {
// We have an incomplete expression.
// Do nothing, just let the user type more stuff.
} else {
words_.push_back("syntax");
words_.push_back(msg);
words_.push_back(errmsg);
clear_raw_input();
}
} else {
words_.push_back(lua_mode);
words_.emplace_back(sv::rtrim(partial));
clear_raw_input();
}
lua_settop(lua_state_, top);
}
void CommonCommands::do_command(const StringVec &words) {