- ## 2.1 statement中的funcstat类别
- function 语句的解析
function aaa(arg, ...)
end
- funcstat解析
static void funcstat(LexState *ls, int line)
{
int needself;
expdesc v, b;
gafqX_next(ls);
needself = funcname(ls, &v); // 解析函数名 needself 是不是有 : 的函数调用
body(ls, &b, needself, line);
gafqK_storevar(ls->fs, &v, &b);
gafqK_fixline(ls->fs, line);
}
- 解析body
// 获取接下去的东西
static void body(LexState *ls, expdesc *e, int needself, int line)
{
checknext(ls, '(');
if (needself)
{
new_localvarliteral(ls, "self", 0);
adjustlocalvars(ls, 1);
}
parlist(ls); // 解析参数列表
checknext(ls, ')');
chunk(ls); // 解析函数的内容
}