From dc4e02846825e0b2ad15576fc99d3c2f5adff572 Mon Sep 17 00:00:00 2001 From: Kyle Evans Date: Sat, 3 Mar 2018 17:13:12 +0000 Subject: [PATCH] liblua: Add loader.interpret This allows lua to pass back a command string to be executed as if it were typed at the loader prompt- loader tries to execute the string first as pure lua, then parses it and gives lua a chance to intercept before it tries to execute it itself. This will be used to implement menu_timeout_command, among other things, which *should* be used to execute basic loader commands independent of the chosen interpreter. --- stand/liblua/lutils.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/stand/liblua/lutils.c b/stand/liblua/lutils.c index 956ffc561b88..4c7a75ae142f 100644 --- a/stand/liblua/lutils.c +++ b/stand/liblua/lutils.c @@ -77,6 +77,25 @@ lua_perform(lua_State *L) return 1; } +/* + * Accepts a space-delimited loader command and runs it through the standard + * loader parsing, as if it were executed at the loader prompt by the user. + */ +static int +lua_interpret(lua_State *L) +{ + const char *interp_string; + + if (lua_gettop(L) != 1) { + lua_pushnil(L); + return 1; + } + + interp_string = luaL_checkstring(L, 1); + lua_pushinteger(L, interp_run(interp_string)); + return 1; +} + static int lua_getchar(lua_State *L) { @@ -305,6 +324,7 @@ lua_writefile(lua_State *L) static const struct luaL_Reg loaderlib[] = { REG_SIMPLE(delay), REG_SIMPLE(command), + REG_SIMPLE(interpret), REG_SIMPLE(getenv), REG_SIMPLE(perform), /* Also registered as the global 'printc' */