Replace upvalue-based shell dispatch with OP_LUSH opcode
Add a dedicated OP_LUSH A B instruction that loads shell C functions directly from the registry, eliminating the need for upvalue allocation in mainfunc(), upvalue population in lua_load(), and the fragile LUSH_NUM_UPVALS heuristic. Every chunk no longer carries 4 extra upvalues.
This commit is contained in:
13
linit.c
13
linit.c
@@ -45,18 +45,19 @@ static const luaL_Reg stdlibs[] = {
|
||||
|
||||
/*
|
||||
** Store shell functions in a registry table at LUA_RIDX_LUSH.
|
||||
** These are populated as upvalues on the main chunk by lua_load().
|
||||
** Integer keys 1..4 hold the C functions (accessed by OP_LUSH).
|
||||
** String key "builtins" holds the builtins table (set by luaopen_builtins).
|
||||
*/
|
||||
static void opencommand (lua_State *L) {
|
||||
lua_createtable(L, 0, 5);
|
||||
lua_createtable(L, LUSH_OP_COUNT, 1);
|
||||
lua_pushcfunction(L, lushCmd_command);
|
||||
lua_setfield(L, -2, "command");
|
||||
lua_rawseti(L, -2, LUSH_OP_COMMAND + 1);
|
||||
lua_pushcfunction(L, lushCmd_interactive);
|
||||
lua_setfield(L, -2, "interactive");
|
||||
lua_rawseti(L, -2, LUSH_OP_INTERACTIVE + 1);
|
||||
lua_pushcfunction(L, lushCmd_getenv);
|
||||
lua_setfield(L, -2, "getenv");
|
||||
lua_rawseti(L, -2, LUSH_OP_GETENV + 1);
|
||||
lua_pushcfunction(L, lushCmd_setenv);
|
||||
lua_setfield(L, -2, "setenv");
|
||||
lua_rawseti(L, -2, LUSH_OP_SETENV + 1);
|
||||
lua_rawseti(L, LUA_REGISTRYINDEX, LUA_RIDX_LUSH);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user