From b8a049abed1f021009930a3030b484e70f89f001 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Tue, 16 Sep 1997 16:25:59 -0300 Subject: Global variables --- lglobal.c | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 lglobal.c (limited to 'lglobal.c') diff --git a/lglobal.c b/lglobal.c new file mode 100644 index 00000000..9f2b9f90 --- /dev/null +++ b/lglobal.c @@ -0,0 +1,71 @@ +/* +** $Id: $ +** Global variables +** See Copyright Notice in lua.h +*/ + +#include + +#include "lbuiltin.h" +#include "lglobal.h" +#include "lmem.h" +#include "lobject.h" +#include "lstring.h" + + +Symbol *luaG_global = NULL; +int luaG_nglobal = 0; +static int maxglobal = 0; + + + +Word luaG_findsymbol (TaggedString *t) +{ + if (maxglobal == 0) { /* first time? */ + maxglobal = 50; + luaG_global = luaM_newvector(maxglobal, Symbol); + luaB_predefine(); + } + if (t->u.s.varindex == NOT_USED) { + if (!t->marked) t->marked = 2; /* avoid GC of global variable names */ + if (luaG_nglobal >= maxglobal) + maxglobal = luaM_growvector(&luaG_global, maxglobal, Symbol, + symbolEM, MAX_WORD); + t->u.s.varindex = luaG_nglobal; + luaG_global[luaG_nglobal].varname = t; + s_ttype(luaG_nglobal) = LUA_T_NIL; + luaG_nglobal++; + } + return t->u.s.varindex; +} + + +Word luaG_findsymbolbyname (char *name) +{ + return luaG_findsymbol(luaS_new(name)); +} + + +int luaG_globaldefined (char *name) +{ + return s_ttype(luaG_findsymbolbyname(name)) != LUA_T_NIL; +} + + +int luaG_nextvar (Word next) +{ + while (next < luaG_nglobal && s_ttype(next) == LUA_T_NIL) + next++; + return (next < luaG_nglobal ? next : -1); +} + + +char *luaG_travsymbol (int (*fn)(TObject *)) +{ + int i; + for (i=0; istr; + return NULL; +} + -- cgit v1.2.3-55-g6feb