diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2002-12-04 13:38:25 -0200 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2002-12-04 13:38:25 -0200 |
| commit | 76de732745d5781fe3ee1af4fd43f01a6c4b8ce4 (patch) | |
| tree | a0f557ac472507dbcfea7ca50d39ad5e1194af01 /lua.c | |
| parent | 90d7892007e399765cf8d14f65f7e3bc4a96e087 (diff) | |
| download | lua-76de732745d5781fe3ee1af4fd43f01a6c4b8ce4.tar.gz lua-76de732745d5781fe3ee1af4fd43f01a6c4b8ce4.tar.bz2 lua-76de732745d5781fe3ee1af4fd43f01a6c4b8ce4.zip | |
avoid non-raw accesses to globals when variable may not exist
Diffstat (limited to 'lua.c')
| -rw-r--r-- | lua.c | 11 |
1 files changed, 7 insertions, 4 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lua.c,v 1.109 2002/11/19 13:49:43 roberto Exp roberto $ | 2 | ** $Id: lua.c,v 1.110 2002/11/25 17:47:13 roberto Exp roberto $ |
| 3 | ** Lua stand-alone interpreter | 3 | ** Lua stand-alone interpreter |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -121,7 +121,8 @@ static int report (int status) { | |||
| 121 | static int lcall (int narg, int clear) { | 121 | static int lcall (int narg, int clear) { |
| 122 | int status; | 122 | int status; |
| 123 | int base = lua_gettop(L) - narg; /* function index */ | 123 | int base = lua_gettop(L) - narg; /* function index */ |
| 124 | lua_getglobal(L, "_TRACEBACK"); /* get traceback function */ | 124 | lua_pushliteral(L, "_TRACEBACK"); |
| 125 | lua_rawget(L, LUA_GLOBALSINDEX); /* get traceback function */ | ||
| 125 | lua_insert(L, base); /* put it under chunk and args */ | 126 | lua_insert(L, base); /* put it under chunk and args */ |
| 126 | signal(SIGINT, laction); | 127 | signal(SIGINT, laction); |
| 127 | status = lua_pcall(L, narg, (clear ? 0 : LUA_MULTRET), base); | 128 | status = lua_pcall(L, narg, (clear ? 0 : LUA_MULTRET), base); |
| @@ -175,7 +176,8 @@ static int dostring (const char *s, const char *name) { | |||
| 175 | 176 | ||
| 176 | 177 | ||
| 177 | static int load_file (const char *name) { | 178 | static int load_file (const char *name) { |
| 178 | lua_getglobal(L, "require"); | 179 | lua_pushliteral(L, "require"); |
| 180 | lua_rawget(L, LUA_GLOBALSINDEX); | ||
| 179 | if (!lua_isfunction(L, -1)) { /* no `require' defined? */ | 181 | if (!lua_isfunction(L, -1)) { /* no `require' defined? */ |
| 180 | lua_pop(L, 1); | 182 | lua_pop(L, 1); |
| 181 | return file_input(name); | 183 | return file_input(name); |
| @@ -228,7 +230,8 @@ static int readline (lua_State *l, const char *prompt) { | |||
| 228 | 230 | ||
| 229 | static const char *get_prompt (int firstline) { | 231 | static const char *get_prompt (int firstline) { |
| 230 | const char *p = NULL; | 232 | const char *p = NULL; |
| 231 | lua_getglobal(L, firstline ? "_PROMPT" : "_PROMPT2"); | 233 | lua_pushstring(L, firstline ? "_PROMPT" : "_PROMPT2"); |
| 234 | lua_rawget(L, LUA_GLOBALSINDEX); | ||
| 232 | p = lua_tostring(L, -1); | 235 | p = lua_tostring(L, -1); |
| 233 | if (p == NULL) p = (firstline ? PROMPT : PROMPT2); | 236 | if (p == NULL) p = (firstline ? PROMPT : PROMPT2); |
| 234 | lua_pop(L, 1); /* remove global */ | 237 | lua_pop(L, 1); /* remove global */ |
