new function lua_nextvar

This commit is contained in:
Roberto Ierusalimschy 1999-02-22 16:13:12 -03:00
parent bb5627f3a4
commit d5feffdb60
4 changed files with 36 additions and 12 deletions

30
lapi.c
View File

@ -1,5 +1,5 @@
/*
** $Id: lapi.c,v 1.35 1999/02/08 17:07:59 roberto Exp roberto $
** $Id: lapi.c,v 1.36 1999/02/12 19:23:02 roberto Exp roberto $
** Lua API
** See Copyright Notice in lua.h
*/
@ -426,10 +426,36 @@ void lua_settag (int tag)
}
TaggedString *luaA_nextvar (TaggedString *g) {
if (g == NULL)
g = (TaggedString *)L->rootglobal.next; /* first variable */
else {
/* check whether name is in global var list */
luaL_arg_check((GCnode *)g != g->head.next, 1, "variable name expected");
g = (TaggedString *)g->head.next; /* get next */
}
while (g && g->u.s.globalval.ttype == LUA_T_NIL) /* skip globals with nil */
g = (TaggedString *)g->head.next;
return g;
}
char *lua_nextvar (char *varname) {
TaggedString *g = (varname == NULL) ? NULL : luaS_new(varname);
g = luaA_nextvar(g);
if (g) {
luaA_pushobject(&g->u.s.globalval);
return g->str;
}
else
return NULL;
}
/*
** {======================================================
** To manipulate the implementation global variables
** To manipulate some state information
** =======================================================
*/

3
lapi.h
View File

@ -1,5 +1,5 @@
/*
** $Id: lapi.h,v 1.1 1997/09/16 19:25:59 roberto Exp roberto $
** $Id: lapi.h,v 1.2 1998/06/19 16:14:09 roberto Exp roberto $
** Auxiliary functions from Lua API
** See Copyright Notice in lua.h
*/
@ -16,5 +16,6 @@ TObject *luaA_Address (lua_Object o);
void luaA_pushobject (TObject *o);
void luaA_packresults (void);
int luaA_passresults (void);
TaggedString *luaA_nextvar (TaggedString *g);
#endif

View File

@ -1,5 +1,5 @@
/*
** $Id: lbuiltin.c,v 1.51 1999/02/12 19:23:02 roberto Exp roberto $
** $Id: lbuiltin.c,v 1.52 1999/02/22 14:17:24 roberto Exp roberto $
** Built-in functions
** See Copyright Notice in lua.h
*/
@ -517,16 +517,12 @@ static void luaB_nextvar (void) {
TObject *o = luaA_Address(luaL_nonnullarg(1));
TaggedString *g;
if (ttype(o) == LUA_T_NIL)
g = (TaggedString *)L->rootglobal.next; /* first variable */
g = NULL;
else {
luaL_arg_check(ttype(o) == LUA_T_STRING, 1, "variable name expected");
g = tsvalue(o); /* find given variable name */
/* check whether name is in global var list */
luaL_arg_check((GCnode *)g != g->head.next, 1, "variable name expected");
g = (TaggedString *)g->head.next; /* get next */
g = tsvalue(o);
}
while (g && g->u.s.globalval.ttype == LUA_T_NIL) /* skip globals with nil */
g = (TaggedString *)g->head.next;
g = luaA_nextvar(g);
if (g) {
pushtagstring(g);
luaA_pushobject(&g->u.s.globalval);

3
lua.h
View File

@ -1,5 +1,5 @@
/*
** $Id: lua.h,v 1.26 1999/01/26 15:31:17 roberto Exp roberto $
** $Id: lua.h,v 1.27 1999/02/09 15:59:22 roberto Exp roberto $
** Lua - An Extensible Extension Language
** TeCGraf: Grupo de Tecnologia em Computacao Grafica, PUC-Rio, Brazil
** e-mail: lua@tecgraf.puc-rio.br
@ -89,6 +89,7 @@ lua_Object lua_rawgettable (void); /* In: table, index */
int lua_tag (lua_Object object);
char *lua_nextvar (char *varname); /* Out: value */
int lua_ref (int lock); /* In: value */
lua_Object lua_getref (int ref);