mirror of
https://github.com/lua/lua.git
synced 2025-01-28 06:03:00 +08:00
new syntax: `... [= name]'
This commit is contained in:
parent
c116dcb92b
commit
5cc448386a
38
lparser.c
38
lparser.c
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
** $Id: lparser.c,v 1.208 2003/04/03 13:35:34 roberto Exp roberto $
|
** $Id: lparser.c,v 1.209 2003/05/13 20:15:59 roberto Exp roberto $
|
||||||
** Lua Parser
|
** Lua Parser
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
@ -173,12 +173,6 @@ static void new_localvarstr (LexState *ls, const char *name, int n) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void create_local (LexState *ls, const char *name) {
|
|
||||||
new_localvarstr(ls, name, 0);
|
|
||||||
adjustlocalvars(ls, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static int indexupvalue (FuncState *fs, TString *name, expdesc *v) {
|
static int indexupvalue (FuncState *fs, TString *name, expdesc *v) {
|
||||||
int i;
|
int i;
|
||||||
Proto *f = fs->f;
|
Proto *f = fs->f;
|
||||||
@ -267,14 +261,19 @@ static void adjust_assign (LexState *ls, int nvars, int nexps, expdesc *e) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void code_params (LexState *ls, int nparams, int dots) {
|
static void code_params (LexState *ls, int nparams, TString *dots) {
|
||||||
FuncState *fs = ls->fs;
|
FuncState *fs = ls->fs;
|
||||||
|
Proto *f = fs->f;
|
||||||
adjustlocalvars(ls, nparams);
|
adjustlocalvars(ls, nparams);
|
||||||
luaX_checklimit(ls, fs->nactvar, MAXPARAMS, "parameters");
|
luaX_checklimit(ls, fs->nactvar, MAXPARAMS, "parameters");
|
||||||
fs->f->numparams = cast(lu_byte, fs->nactvar);
|
f->numparams = cast(lu_byte, fs->nactvar);
|
||||||
fs->f->is_vararg = cast(lu_byte, dots);
|
if (!dots)
|
||||||
if (dots)
|
f->is_vararg = 0;
|
||||||
create_local(ls, "arg");
|
else {
|
||||||
|
f->is_vararg = 1;
|
||||||
|
new_localvar(ls, dots, 0);
|
||||||
|
adjustlocalvars(ls, 1);
|
||||||
|
}
|
||||||
luaK_reserveregs(fs, fs->nactvar); /* reserve register for parameters */
|
luaK_reserveregs(fs, fs->nactvar); /* reserve register for parameters */
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -528,12 +527,17 @@ static void constructor (LexState *ls, expdesc *t) {
|
|||||||
static void parlist (LexState *ls) {
|
static void parlist (LexState *ls) {
|
||||||
/* parlist -> [ param { `,' param } ] */
|
/* parlist -> [ param { `,' param } ] */
|
||||||
int nparams = 0;
|
int nparams = 0;
|
||||||
int dots = 0;
|
TString *dots = NULL;
|
||||||
if (ls->t.token != ')') { /* is `parlist' not empty? */
|
if (ls->t.token != ')') { /* is `parlist' not empty? */
|
||||||
do {
|
do {
|
||||||
switch (ls->t.token) {
|
switch (ls->t.token) {
|
||||||
case TK_DOTS: dots = 1; next(ls); break;
|
|
||||||
case TK_NAME: new_localvar(ls, str_checkname(ls), nparams++); break;
|
case TK_NAME: new_localvar(ls, str_checkname(ls), nparams++); break;
|
||||||
|
case TK_DOTS: {
|
||||||
|
next(ls);
|
||||||
|
dots = (testnext(ls, '=')) ? str_checkname(ls) :
|
||||||
|
luaS_new(ls->L, "arg");
|
||||||
|
break;
|
||||||
|
}
|
||||||
default: luaX_syntaxerror(ls, "<name> or `...' expected");
|
default: luaX_syntaxerror(ls, "<name> or `...' expected");
|
||||||
}
|
}
|
||||||
} while (!dots && testnext(ls, ','));
|
} while (!dots && testnext(ls, ','));
|
||||||
@ -548,8 +552,10 @@ static void body (LexState *ls, expdesc *e, int needself, int line) {
|
|||||||
open_func(ls, &new_fs);
|
open_func(ls, &new_fs);
|
||||||
new_fs.f->lineDefined = line;
|
new_fs.f->lineDefined = line;
|
||||||
check(ls, '(');
|
check(ls, '(');
|
||||||
if (needself)
|
if (needself) {
|
||||||
create_local(ls, "self");
|
new_localvarstr(ls, "self", 0);
|
||||||
|
adjustlocalvars(ls, 1);
|
||||||
|
}
|
||||||
parlist(ls);
|
parlist(ls);
|
||||||
check(ls, ')');
|
check(ls, ')');
|
||||||
chunk(ls);
|
chunk(ls);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user