Refactor: extract lookup_lush_func, reorder helpers, eliminate forward decl

Extract lookup_lush_func() in lcmd.c to deduplicate the registry lookup
pattern shared by try_builtin and exec_user_command. Move exec_user_command
after exec_failed to group helpers together. Move codeenvget definition in
lparser.c to replace its forward declaration.
This commit is contained in:
Cormac Shannon
2026-03-22 17:04:02 +00:00
parent 973dd90d65
commit 9bc7dc01b7
2 changed files with 189 additions and 249 deletions

View File

@@ -553,7 +553,20 @@ static void singlevar (LexState *ls, expdesc *var) {
}
static void codeenvget (LexState *ls, expdesc *v, TString *name);
static void codeenvget (LexState *ls, expdesc *v, TString *name) {
FuncState *fs = ls->fs;
int base, line;
expdesc func, arg;
line = ls->linenumber;
codelushfunc(fs, LUSH_OP_GETENV, &func);
base = func.u.info;
codestring(&arg, name);
luaK_exp2nextreg(fs, &arg);
init_exp(v, VCALL, luaK_codeABC(fs, OP_CALL, base, 2, 2));
luaK_fixline(fs, line);
fs->freereg = cast_byte(base + 1);
}
/*
** Parse a single interpolation fragment in a command: ${expr}, $NAME,
@@ -1323,21 +1336,6 @@ static void commandexp (LexState *ls, expdesc *v) {
}
static void codeenvget (LexState *ls, expdesc *v, TString *name) {
FuncState *fs = ls->fs;
int base, line;
expdesc func, arg;
line = ls->linenumber;
codelushfunc(fs, LUSH_OP_GETENV, &func);
base = func.u.info;
codestring(&arg, name);
luaK_exp2nextreg(fs, &arg);
init_exp(v, VCALL, luaK_codeABC(fs, OP_CALL, base, 2, 2));
luaK_fixline(fs, line);
fs->freereg = cast_byte(base + 1);
}
static void primaryexp (LexState *ls, expdesc *v) {
/* primaryexp -> NAME | '(' expr ')' | COMMAND | ENVVAR */
switch (ls->t.token) {