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

@@ -6,6 +6,7 @@
#include "luaconsole.hpp"
#include "util.hpp"
#include "printbuffer.hpp"
#include "luastack.hpp"
#include <memory>
@@ -33,10 +34,14 @@ public:
eng::vector<Invocation> delayed_invocations_;
int64_t admin_id_ = 0;
double next_tick_ = 0;
lua_State *lua_syntax_checker_;
public:
LpxServer()
{
// Create a little lua interpreter for syntax checking only.
lua_syntax_checker_ = LuaCoreStack::newstate(eng::l_alloc);
// Create the master world model.
master_.reset(new World(WORLD_TYPE_MASTER));
@@ -62,6 +67,10 @@ public:
rescan_lua_source(true);
}
~LpxServer() {
lua_close(lua_syntax_checker_);
}
virtual void do_syntax_error(std::string_view error) override {
stdostream() << "Syntax error: " << error << std::endl;
}
@@ -178,6 +187,13 @@ public:
master_->rollback();
break;
}
case AccessKind::VALIDATE_LUA: {
LuaVar closure;
LuaDefStack LS(lua_syntax_checker_, closure);
eng::string errmsg = LS.load(closure, datapk, "stdin");
retpk->write_bytes(errmsg);
break;
}
default: {
stdostream() << "Invalid event_access: " << int(kind) << std::endl;
}