diff --git a/lauxlib.c b/lauxlib.c index 2d16c9ce..2c261077 100644 --- a/lauxlib.c +++ b/lauxlib.c @@ -1,5 +1,5 @@ /* -** $Id: lauxlib.c,v 1.289 2016/12/20 18:37:00 roberto Exp roberto $ +** $Id: lauxlib.c,v 1.290 2017/04/24 18:06:12 roberto Exp roberto $ ** Auxiliary functions for building Lua libraries ** See Copyright Notice in lua.h */ @@ -76,7 +76,7 @@ static int pushglobalfuncname (lua_State *L, lua_Debug *ar) { lua_getfield(L, LUA_REGISTRYINDEX, LUA_LOADED_TABLE); if (findfield(L, top + 1, 2)) { const char *name = lua_tostring(L, -1); - if (strncmp(name, "_G.", 3) == 0) { /* name start with '_G.'? */ + if (strncmp(name, LUA_GNAME ".", 3) == 0) { /* name start with '_G.'? */ lua_pushstring(L, name + 3); /* push name without prefix */ lua_remove(L, -2); /* remove original name */ } diff --git a/lauxlib.h b/lauxlib.h index 8de19916..79d1f30a 100644 --- a/lauxlib.h +++ b/lauxlib.h @@ -1,5 +1,5 @@ /* -** $Id: lauxlib.h,v 1.131 2016/12/06 14:54:31 roberto Exp roberto $ +** $Id: lauxlib.h,v 1.132 2017/04/24 18:06:12 roberto Exp roberto $ ** Auxiliary functions for building Lua libraries ** See Copyright Notice in lua.h */ @@ -15,6 +15,10 @@ #include "lua.h" +/* global table */ +#define LUA_GNAME "_G" + + /* extra error code for 'luaL_loadfilex' */ #define LUA_ERRFILE (LUA_ERRERR+1) diff --git a/lbaselib.c b/lbaselib.c index 55b56f35..87b0ce83 100644 --- a/lbaselib.c +++ b/lbaselib.c @@ -1,5 +1,5 @@ /* -** $Id: lbaselib.c,v 1.315 2017/02/23 21:07:34 roberto Exp roberto $ +** $Id: lbaselib.c,v 1.316 2017/05/26 19:14:29 roberto Exp roberto $ ** Basic library ** See Copyright Notice in lua.h */ @@ -504,7 +504,7 @@ static const luaL_Reg base_funcs[] = { {"type", luaB_type}, {"xpcall", luaB_xpcall}, /* placeholders */ - {"_G", NULL}, + {LUA_GNAME, NULL}, {"_VERSION", NULL}, {NULL, NULL} }; @@ -516,7 +516,7 @@ LUAMOD_API int luaopen_base (lua_State *L) { luaL_setfuncs(L, base_funcs, 0); /* set global _G */ lua_pushvalue(L, -1); - lua_setfield(L, -2, "_G"); + lua_setfield(L, -2, LUA_GNAME); /* set global _VERSION */ lua_pushliteral(L, LUA_VERSION); lua_setfield(L, -2, "_VERSION"); diff --git a/linit.c b/linit.c index 897ae352..3c2b6023 100644 --- a/linit.c +++ b/linit.c @@ -1,5 +1,5 @@ /* -** $Id: linit.c,v 1.38 2015/01/05 13:48:33 roberto Exp roberto $ +** $Id: linit.c,v 1.39 2016/12/04 20:17:24 roberto Exp roberto $ ** Initialization of libraries for lua.c and other clients ** See Copyright Notice in lua.h */ @@ -40,7 +40,7 @@ ** program */ static const luaL_Reg loadedlibs[] = { - {"_G", luaopen_base}, + {LUA_GNAME, luaopen_base}, {LUA_LOADLIBNAME, luaopen_package}, {LUA_COLIBNAME, luaopen_coroutine}, {LUA_TABLIBNAME, luaopen_table}, diff --git a/ltests.c b/ltests.c index 8b2c0ee1..36da64e8 100644 --- a/ltests.c +++ b/ltests.c @@ -1,5 +1,5 @@ /* -** $Id: ltests.c,v 2.220 2017/06/12 14:21:44 roberto Exp roberto $ +** $Id: ltests.c,v 2.221 2017/06/27 11:35:31 roberto Exp roberto $ ** Internal Module for Debugging of the Lua Implementation ** See Copyright Notice in lua.h */ @@ -960,7 +960,7 @@ static lua_State *getstate (lua_State *L) { static int loadlib (lua_State *L) { static const luaL_Reg libs[] = { - {"_G", luaopen_base}, + {LUA_GNAME, luaopen_base}, {"coroutine", luaopen_coroutine}, {"debug", luaopen_debug}, {"io", luaopen_io},