diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2017-06-27 15:32:49 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2017-06-27 15:32:49 -0300 |
commit | 5a1c8d8ef343bf0157851a4832c2c937b812b64f (patch) | |
tree | 61948343a233dae64a1d02b7c77b00f5b7eba6da | |
parent | 124bfd20817d4624d2b69a4dc41182485912b821 (diff) | |
download | lua-5a1c8d8ef343bf0157851a4832c2c937b812b64f.tar.gz lua-5a1c8d8ef343bf0157851a4832c2c937b812b64f.tar.bz2 lua-5a1c8d8ef343bf0157851a4832c2c937b812b64f.zip |
new constant 'LUA_GNAME' for the name of the global table "_G"
-rw-r--r-- | lauxlib.c | 4 | ||||
-rw-r--r-- | lauxlib.h | 6 | ||||
-rw-r--r-- | lbaselib.c | 6 | ||||
-rw-r--r-- | linit.c | 4 | ||||
-rw-r--r-- | ltests.c | 4 |
5 files changed, 14 insertions, 10 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lauxlib.c,v 1.289 2016/12/20 18:37:00 roberto Exp roberto $ | 2 | ** $Id: lauxlib.c,v 1.290 2017/04/24 18:06:12 roberto Exp roberto $ |
3 | ** Auxiliary functions for building Lua libraries | 3 | ** Auxiliary functions for building Lua libraries |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -76,7 +76,7 @@ static int pushglobalfuncname (lua_State *L, lua_Debug *ar) { | |||
76 | lua_getfield(L, LUA_REGISTRYINDEX, LUA_LOADED_TABLE); | 76 | lua_getfield(L, LUA_REGISTRYINDEX, LUA_LOADED_TABLE); |
77 | if (findfield(L, top + 1, 2)) { | 77 | if (findfield(L, top + 1, 2)) { |
78 | const char *name = lua_tostring(L, -1); | 78 | const char *name = lua_tostring(L, -1); |
79 | if (strncmp(name, "_G.", 3) == 0) { /* name start with '_G.'? */ | 79 | if (strncmp(name, LUA_GNAME ".", 3) == 0) { /* name start with '_G.'? */ |
80 | lua_pushstring(L, name + 3); /* push name without prefix */ | 80 | lua_pushstring(L, name + 3); /* push name without prefix */ |
81 | lua_remove(L, -2); /* remove original name */ | 81 | lua_remove(L, -2); /* remove original name */ |
82 | } | 82 | } |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lauxlib.h,v 1.131 2016/12/06 14:54:31 roberto Exp roberto $ | 2 | ** $Id: lauxlib.h,v 1.132 2017/04/24 18:06:12 roberto Exp roberto $ |
3 | ** Auxiliary functions for building Lua libraries | 3 | ** Auxiliary functions for building Lua libraries |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -15,6 +15,10 @@ | |||
15 | #include "lua.h" | 15 | #include "lua.h" |
16 | 16 | ||
17 | 17 | ||
18 | /* global table */ | ||
19 | #define LUA_GNAME "_G" | ||
20 | |||
21 | |||
18 | 22 | ||
19 | /* extra error code for 'luaL_loadfilex' */ | 23 | /* extra error code for 'luaL_loadfilex' */ |
20 | #define LUA_ERRFILE (LUA_ERRERR+1) | 24 | #define LUA_ERRFILE (LUA_ERRERR+1) |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lbaselib.c,v 1.315 2017/02/23 21:07:34 roberto Exp roberto $ | 2 | ** $Id: lbaselib.c,v 1.316 2017/05/26 19:14:29 roberto Exp roberto $ |
3 | ** Basic library | 3 | ** Basic library |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -504,7 +504,7 @@ static const luaL_Reg base_funcs[] = { | |||
504 | {"type", luaB_type}, | 504 | {"type", luaB_type}, |
505 | {"xpcall", luaB_xpcall}, | 505 | {"xpcall", luaB_xpcall}, |
506 | /* placeholders */ | 506 | /* placeholders */ |
507 | {"_G", NULL}, | 507 | {LUA_GNAME, NULL}, |
508 | {"_VERSION", NULL}, | 508 | {"_VERSION", NULL}, |
509 | {NULL, NULL} | 509 | {NULL, NULL} |
510 | }; | 510 | }; |
@@ -516,7 +516,7 @@ LUAMOD_API int luaopen_base (lua_State *L) { | |||
516 | luaL_setfuncs(L, base_funcs, 0); | 516 | luaL_setfuncs(L, base_funcs, 0); |
517 | /* set global _G */ | 517 | /* set global _G */ |
518 | lua_pushvalue(L, -1); | 518 | lua_pushvalue(L, -1); |
519 | lua_setfield(L, -2, "_G"); | 519 | lua_setfield(L, -2, LUA_GNAME); |
520 | /* set global _VERSION */ | 520 | /* set global _VERSION */ |
521 | lua_pushliteral(L, LUA_VERSION); | 521 | lua_pushliteral(L, LUA_VERSION); |
522 | lua_setfield(L, -2, "_VERSION"); | 522 | lua_setfield(L, -2, "_VERSION"); |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: linit.c,v 1.38 2015/01/05 13:48:33 roberto Exp roberto $ | 2 | ** $Id: linit.c,v 1.39 2016/12/04 20:17:24 roberto Exp roberto $ |
3 | ** Initialization of libraries for lua.c and other clients | 3 | ** Initialization of libraries for lua.c and other clients |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -40,7 +40,7 @@ | |||
40 | ** program | 40 | ** program |
41 | */ | 41 | */ |
42 | static const luaL_Reg loadedlibs[] = { | 42 | static const luaL_Reg loadedlibs[] = { |
43 | {"_G", luaopen_base}, | 43 | {LUA_GNAME, luaopen_base}, |
44 | {LUA_LOADLIBNAME, luaopen_package}, | 44 | {LUA_LOADLIBNAME, luaopen_package}, |
45 | {LUA_COLIBNAME, luaopen_coroutine}, | 45 | {LUA_COLIBNAME, luaopen_coroutine}, |
46 | {LUA_TABLIBNAME, luaopen_table}, | 46 | {LUA_TABLIBNAME, luaopen_table}, |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ltests.c,v 2.220 2017/06/12 14:21:44 roberto Exp roberto $ | 2 | ** $Id: ltests.c,v 2.221 2017/06/27 11:35:31 roberto Exp roberto $ |
3 | ** Internal Module for Debugging of the Lua Implementation | 3 | ** Internal Module for Debugging of the Lua Implementation |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -960,7 +960,7 @@ static lua_State *getstate (lua_State *L) { | |||
960 | 960 | ||
961 | static int loadlib (lua_State *L) { | 961 | static int loadlib (lua_State *L) { |
962 | static const luaL_Reg libs[] = { | 962 | static const luaL_Reg libs[] = { |
963 | {"_G", luaopen_base}, | 963 | {LUA_GNAME, luaopen_base}, |
964 | {"coroutine", luaopen_coroutine}, | 964 | {"coroutine", luaopen_coroutine}, |
965 | {"debug", luaopen_debug}, | 965 | {"debug", luaopen_debug}, |
966 | {"io", luaopen_io}, | 966 | {"io", luaopen_io}, |