diff options
| author | Diego Nehab <diego@impa.br> | 2013-05-29 16:56:56 +0800 |
|---|---|---|
| committer | Diego Nehab <diego@impa.br> | 2013-05-29 16:56:56 +0800 |
| commit | 79e6c4915d267e149e1f3b134901bf355d439c15 (patch) | |
| tree | fded0a926a268d88710e652fa8cdf06ec77cf217 /src/luasocket.c | |
| parent | 5167ddaf499cf198b10208a2f76c27629e99ae1b (diff) | |
| download | luasocket-79e6c4915d267e149e1f3b134901bf355d439c15.tar.gz luasocket-79e6c4915d267e149e1f3b134901bf355d439c15.tar.bz2 luasocket-79e6c4915d267e149e1f3b134901bf355d439c15.zip | |
Export global only if LUA_COMPAT_MODULE defined.
Diffstat (limited to 'src/luasocket.c')
| -rw-r--r-- | src/luasocket.c | 25 |
1 files changed, 5 insertions, 20 deletions
diff --git a/src/luasocket.c b/src/luasocket.c index bea23d7..e6ee747 100644 --- a/src/luasocket.c +++ b/src/luasocket.c | |||
| @@ -79,31 +79,11 @@ static int global_unload(lua_State *L) { | |||
| 79 | } | 79 | } |
| 80 | 80 | ||
| 81 | #if LUA_VERSION_NUM > 501 | 81 | #if LUA_VERSION_NUM > 501 |
| 82 | |||
| 83 | int luaL_typerror (lua_State *L, int narg, const char *tname) { | 82 | int luaL_typerror (lua_State *L, int narg, const char *tname) { |
| 84 | const char *msg = lua_pushfstring(L, "%s expected, got %s", | 83 | const char *msg = lua_pushfstring(L, "%s expected, got %s", |
| 85 | tname, luaL_typename(L, narg)); | 84 | tname, luaL_typename(L, narg)); |
| 86 | return luaL_argerror(L, narg, msg); | 85 | return luaL_argerror(L, narg, msg); |
| 87 | } | 86 | } |
| 88 | |||
| 89 | #if ! defined(LUA_COMPAT_MODULE) | ||
| 90 | void luaL_openlib(lua_State *L, const char *name, const luaL_Reg *funcs, int idx) { | ||
| 91 | if (name != NULL) { | ||
| 92 | #ifdef LUASOCKET_USE_GLOBAL | ||
| 93 | lua_getglobal(L,name); | ||
| 94 | if (lua_isnil(L,-1)) { | ||
| 95 | lua_newtable(L); | ||
| 96 | lua_setglobal(L,name); | ||
| 97 | lua_getglobal(L,name); | ||
| 98 | } | ||
| 99 | #else | ||
| 100 | lua_newtable(L); | ||
| 101 | #endif | ||
| 102 | } | ||
| 103 | luaL_setfuncs(L,funcs,0); | ||
| 104 | } | ||
| 105 | #endif | ||
| 106 | |||
| 107 | #endif | 87 | #endif |
| 108 | 88 | ||
| 109 | /*-------------------------------------------------------------------------*\ | 89 | /*-------------------------------------------------------------------------*\ |
| @@ -112,7 +92,12 @@ void luaL_openlib(lua_State *L, const char *name, const luaL_Reg *funcs, int idx | |||
| 112 | static int base_open(lua_State *L) { | 92 | static int base_open(lua_State *L) { |
| 113 | if (socket_open()) { | 93 | if (socket_open()) { |
| 114 | /* export functions (and leave namespace table on top of stack) */ | 94 | /* export functions (and leave namespace table on top of stack) */ |
| 95 | #if LUA_VERSION_NUM > 501 && !defined(LUA_COMPAT_MODULE) | ||
| 96 | lua_newtable(L); | ||
| 97 | luaL_setfuncs(L, func, 0); | ||
| 98 | #else | ||
| 115 | luaL_openlib(L, "socket", func, 0); | 99 | luaL_openlib(L, "socket", func, 0); |
| 100 | #endif | ||
| 116 | #ifdef LUASOCKET_DEBUG | 101 | #ifdef LUASOCKET_DEBUG |
| 117 | lua_pushstring(L, "_DEBUG"); | 102 | lua_pushstring(L, "_DEBUG"); |
| 118 | lua_pushboolean(L, 1); | 103 | lua_pushboolean(L, 1); |
