mirror of https://github.com/lua/lua
avoid using deprecated macros lua_[gs]etglobal
This commit is contained in:
parent
3a9ae612a4
commit
2e51792596
10
lbaselib.c
10
lbaselib.c
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
** $Id: lbaselib.c,v 1.229 2009/11/27 15:38:51 roberto Exp roberto $
|
||||
** $Id: lbaselib.c,v 1.230 2009/12/10 18:17:37 roberto Exp roberto $
|
||||
** Basic library
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
|
@ -23,7 +23,7 @@
|
|||
static int luaB_print (lua_State *L) {
|
||||
int n = lua_gettop(L); /* number of arguments */
|
||||
int i;
|
||||
lua_getglobal(L, "tostring");
|
||||
lua_getfield(L, LUA_GLOBALSINDEX, "tostring");
|
||||
for (i=1; i<=n; i++) {
|
||||
const char *s;
|
||||
size_t l;
|
||||
|
@ -695,11 +695,11 @@ static void auxopen (lua_State *L, const char *name,
|
|||
static void base_open (lua_State *L) {
|
||||
/* set global _G */
|
||||
lua_pushvalue(L, LUA_GLOBALSINDEX);
|
||||
lua_setglobal(L, "_G");
|
||||
lua_setfield(L, LUA_GLOBALSINDEX, "_G");
|
||||
/* open lib into global table */
|
||||
luaL_register(L, "_G", base_funcs);
|
||||
lua_pushliteral(L, LUA_VERSION);
|
||||
lua_setglobal(L, "_VERSION"); /* set global _VERSION */
|
||||
lua_setfield(L, LUA_GLOBALSINDEX, "_VERSION"); /* set global _VERSION */
|
||||
/* `ipairs' and `pairs' need auxiliary functions as upvalues */
|
||||
auxopen(L, "ipairs", luaB_ipairs, ipairsaux);
|
||||
auxopen(L, "pairs", luaB_pairs, luaB_next);
|
||||
|
@ -710,7 +710,7 @@ static void base_open (lua_State *L) {
|
|||
lua_pushliteral(L, "kv");
|
||||
lua_setfield(L, -2, "__mode"); /* metatable(w).__mode = "kv" */
|
||||
lua_pushcclosure(L, luaB_newproxy, 1);
|
||||
lua_setglobal(L, "newproxy"); /* set global `newproxy' */
|
||||
lua_setfield(L, LUA_GLOBALSINDEX, "newproxy"); /* set global `newproxy' */
|
||||
}
|
||||
|
||||
|
||||
|
|
4
linit.c
4
linit.c
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
** $Id: linit.c,v 1.19 2009/07/01 16:16:40 roberto Exp roberto $
|
||||
** $Id: linit.c,v 1.20 2009/09/05 12:39:29 roberto Exp roberto $
|
||||
** Initialization of libraries for lua.c and other clients
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
|
@ -64,7 +64,7 @@ LUALIB_API void luaL_openlibs (lua_State *L) {
|
|||
}
|
||||
lua_pop(L, 1); /* remove package.preload table */
|
||||
#ifdef LUA_COMPAT_DEBUGLIB
|
||||
lua_getglobal(L, "require");
|
||||
lua_getfield(L, LUA_GLOBALSINDEX, "require");
|
||||
lua_pushliteral(L, LUA_DBLIBNAME);
|
||||
lua_call(L, 1, 0); /* call 'require"debug"' */
|
||||
#endif
|
||||
|
|
8
lua.c
8
lua.c
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
** $Id: lua.c,v 1.175 2009/08/10 16:23:19 roberto Exp roberto $
|
||||
** $Id: lua.c,v 1.176 2009/11/24 18:05:12 roberto Exp roberto $
|
||||
** Lua stand-alone interpreter
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
|
@ -151,7 +151,7 @@ static int dostring (lua_State *L, const char *s, const char *name) {
|
|||
|
||||
|
||||
static int dolibrary (lua_State *L, const char *name) {
|
||||
lua_getglobal(L, "require");
|
||||
lua_getfield(L, LUA_GLOBALSINDEX, "require");
|
||||
lua_pushstring(L, name);
|
||||
return report(L, docall(L, 1, 1));
|
||||
}
|
||||
|
@ -231,7 +231,7 @@ static void dotty (lua_State *L) {
|
|||
report(L, status);
|
||||
if (status == LUA_OK && lua_gettop(L) > 0) { /* any result to print? */
|
||||
luaL_checkstack(L, LUA_MINSTACK, "too many results to print");
|
||||
lua_getglobal(L, "print");
|
||||
lua_getfield(L, LUA_GLOBALSINDEX, "print");
|
||||
lua_insert(L, 1);
|
||||
if (lua_pcall(L, lua_gettop(L)-1, 0, 0) != LUA_OK)
|
||||
l_message(progname, lua_pushfstring(L,
|
||||
|
@ -250,7 +250,7 @@ static int handle_script (lua_State *L, char **argv, int n) {
|
|||
int status;
|
||||
const char *fname;
|
||||
int narg = getargs(L, argv, n); /* collect arguments */
|
||||
lua_setglobal(L, "arg");
|
||||
lua_setfield(L, LUA_GLOBALSINDEX, "arg");
|
||||
fname = argv[n];
|
||||
if (strcmp(fname, "-") == 0 && strcmp(argv[n-1], "--") != 0)
|
||||
fname = NULL; /* stdin */
|
||||
|
|
5
lua.h
5
lua.h
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
** $Id: lua.h,v 1.251 2009/11/25 15:27:51 roberto Exp roberto $
|
||||
** $Id: lua.h,v 1.252 2009/11/26 11:39:20 roberto Exp roberto $
|
||||
** Lua - A Scripting Language
|
||||
** Lua.org, PUC-Rio, Brazil (http://www.lua.org)
|
||||
** See Copyright Notice at the end of this file
|
||||
|
@ -297,7 +297,8 @@ LUA_API void (lua_setallocf) (lua_State *L, lua_Alloc f, void *ud);
|
|||
|
||||
#define lua_newtable(L) lua_createtable(L, 0, 0)
|
||||
|
||||
#define lua_register(L,n,f) (lua_pushcfunction(L, (f)), lua_setglobal(L, (n)))
|
||||
#define lua_register(L,n,f) \
|
||||
(lua_pushcfunction(L, (f)), lua_setfield(L, LUA_GLOBALSINDEX, (n)))
|
||||
|
||||
#define lua_pushcfunction(L,f) lua_pushcclosure(L, (f), 0)
|
||||
|
||||
|
|
Loading…
Reference in New Issue