Console overhaul, part 2. New console is mostly working.
This commit is contained in:
@@ -32,7 +32,7 @@ enum class AccessKind {
|
||||
INVOKE_LUA_SOURCE,
|
||||
PROBE_LUA_CALL,
|
||||
CONNECT_TO_SERVER,
|
||||
VALIDATE_LUA,
|
||||
VALIDATE_LUA_EXPR,
|
||||
};
|
||||
|
||||
class DrivenEngine;
|
||||
|
||||
@@ -263,7 +263,7 @@ public:
|
||||
set_initial_state_connect(util::ss("nocert:", datapk, ":8085"));
|
||||
break;
|
||||
}
|
||||
case AccessKind::VALIDATE_LUA: {
|
||||
case AccessKind::VALIDATE_LUA_EXPR: {
|
||||
LuaVar closure;
|
||||
LuaExtStack LS(lua_syntax_checker_, closure);
|
||||
eng::string errmsg = LS.load(closure, datapk, "stdin");
|
||||
|
||||
@@ -187,7 +187,7 @@ public:
|
||||
master_->rollback();
|
||||
break;
|
||||
}
|
||||
case AccessKind::VALIDATE_LUA: {
|
||||
case AccessKind::VALIDATE_LUA_EXPR: {
|
||||
LuaVar closure;
|
||||
LuaExtStack LS(lua_syntax_checker_, closure);
|
||||
eng::string errmsg = LS.load(closure, datapk, "stdin");
|
||||
|
||||
@@ -325,6 +325,14 @@ bool LuaCoreStack::next(LuaSlot tab, LuaSlot key, LuaSlot value) const {
|
||||
|
||||
eng::string LuaCoreStack::load(LuaSlot result, std::string_view code, std::string_view context)
|
||||
{
|
||||
// We interpret "=x" as syntactic sugar for "return x"
|
||||
eng::string expanded;
|
||||
if (sv::has_prefix(code, "="))
|
||||
{
|
||||
expanded = eng::string("return ") + eng::string(code.substr(1));
|
||||
code = expanded;
|
||||
}
|
||||
|
||||
eng::string fullcontext = eng::string("=") + eng::string(context);
|
||||
luaL_loadbuffer(L_, code.data(), code.size(), fullcontext.c_str());
|
||||
int type = lua_type(L_, -1);
|
||||
|
||||
@@ -874,9 +874,8 @@ void World::invoke_lua_expr(int64_t actor_id, int64_t place_id, std::string_view
|
||||
LuaExtStack LS(L, func);
|
||||
|
||||
// create the compiled closure.
|
||||
int status = luaL_loadbuffer(L, datapack.data(), datapack.size(), "=invoke");
|
||||
lua_replace(L, func.index());
|
||||
if (status != LUA_OK) {
|
||||
eng::string error = LS.load(func, datapack, "=invoke");
|
||||
if (!error.empty()) {
|
||||
// The closure is actually an error message. Do nothing.
|
||||
// This should normally not happen: LuaConsole should filter
|
||||
// out syntax errors.
|
||||
|
||||
Reference in New Issue
Block a user