diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2000-05-08 16:32:53 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2000-05-08 16:32:53 -0300 |
commit | 11a70220670f25a9929439f0b27331f09f05235c (patch) | |
tree | c4a962b5a3e53ac6df8894fb3ad2248c4a1256cb /llex.c | |
parent | 35a6ed283881f313152457f24cc6c677122d5058 (diff) | |
download | lua-11a70220670f25a9929439f0b27331f09f05235c.tar.gz lua-11a70220670f25a9929439f0b27331f09f05235c.tar.bz2 lua-11a70220670f25a9929439f0b27331f09f05235c.zip |
global variables are stored in a Lua table
Diffstat (limited to 'llex.c')
-rw-r--r-- | llex.c | 11 |
1 files changed, 9 insertions, 2 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: llex.c,v 1.56 2000/04/07 13:11:49 roberto Exp roberto $ | 2 | ** $Id: llex.c,v 1.57 2000/04/12 18:57:19 roberto Exp roberto $ |
3 | ** Lexical Analyzer | 3 | ** Lexical Analyzer |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -18,6 +18,7 @@ | |||
18 | #include "lparser.h" | 18 | #include "lparser.h" |
19 | #include "lstate.h" | 19 | #include "lstate.h" |
20 | #include "lstring.h" | 20 | #include "lstring.h" |
21 | #include "ltable.h" | ||
21 | #include "luadebug.h" | 22 | #include "luadebug.h" |
22 | #include "lzio.h" | 23 | #include "lzio.h" |
23 | 24 | ||
@@ -121,12 +122,18 @@ static void skipspace (LexState *LS) { | |||
121 | } | 122 | } |
122 | 123 | ||
123 | 124 | ||
125 | static int globaldefined (lua_State *L, const char *name) { | ||
126 | const TObject *value = luaH_getglobal(L, name); | ||
127 | return ttype(value) != TAG_NIL; | ||
128 | } | ||
129 | |||
130 | |||
124 | static int checkcond (lua_State *L, LexState *LS, const char *buff) { | 131 | static int checkcond (lua_State *L, LexState *LS, const char *buff) { |
125 | static const char *const opts[] = {"nil", "1", NULL}; | 132 | static const char *const opts[] = {"nil", "1", NULL}; |
126 | int i = luaL_findstring(buff, opts); | 133 | int i = luaL_findstring(buff, opts); |
127 | if (i >= 0) return i; | 134 | if (i >= 0) return i; |
128 | else if (isalpha((unsigned char)buff[0]) || buff[0] == '_') | 135 | else if (isalpha((unsigned char)buff[0]) || buff[0] == '_') |
129 | return luaS_globaldefined(L, buff); | 136 | return globaldefined(L, buff); |
130 | else { | 137 | else { |
131 | luaX_syntaxerror(LS, "invalid $if condition", buff); | 138 | luaX_syntaxerror(LS, "invalid $if condition", buff); |
132 | return 0; /* to avoid warnings */ | 139 | return 0; /* to avoid warnings */ |