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:
30
lparser.c
30
lparser.c
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user