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

@@ -323,6 +323,29 @@ bool LuaCoreStack::next(LuaSlot tab, LuaSlot key, LuaSlot value) const {
return (ret != 0);
}
eng::string LuaCoreStack::load(LuaSlot result, std::string_view code, std::string_view context)
{
eng::string fullcontext = eng::string("=") + eng::string(context);
luaL_loadbuffer(L_, code.data(), code.size(), fullcontext.c_str());
int type = lua_type(L_, -1);
if (type == LUA_TFUNCTION) {
// compiler returned a closure.
lua_replace(L_, result.index());
return "";
} else if (type == LUA_TSTRING) {
// compiler returned an error message.
size_t len;
const char *str = lua_tolstring(L_, -1, &len);
eng::string message(str, len);
lua_pop(L_, 1);
if (message.empty()) message = "unknown compiler error";
set(result, message);
return message;
} else {
assert(false && "lua compiler didn't return a closure, but didn't return an error message either");
}
}
void LuaCoreStack::getglobaltable(LuaSlot target) const {
lua_pushglobaltable(L_);
lua_replace(L_, target);