Export global only if LUA_COMPAT_MODULE defined.

This commit is contained in:
Diego Nehab 2013-05-29 16:56:56 +08:00
parent 5167ddaf49
commit 79e6c4915d
11 changed files with 55 additions and 37 deletions

View file

@ -79,31 +79,11 @@ static int global_unload(lua_State *L) {
}
#if LUA_VERSION_NUM > 501
int luaL_typerror (lua_State *L, int narg, const char *tname) {
const char *msg = lua_pushfstring(L, "%s expected, got %s",
tname, luaL_typename(L, narg));
return luaL_argerror(L, narg, msg);
}
#if ! defined(LUA_COMPAT_MODULE)
void luaL_openlib(lua_State *L, const char *name, const luaL_Reg *funcs, int idx) {
if (name != NULL) {
#ifdef LUASOCKET_USE_GLOBAL
lua_getglobal(L,name);
if (lua_isnil(L,-1)) {
lua_newtable(L);
lua_setglobal(L,name);
lua_getglobal(L,name);
}
#else
lua_newtable(L);
#endif
}
luaL_setfuncs(L,funcs,0);
}
#endif
#endif
/*-------------------------------------------------------------------------*\
@ -112,7 +92,12 @@ void luaL_openlib(lua_State *L, const char *name, const luaL_Reg *funcs, int idx
static int base_open(lua_State *L) {
if (socket_open()) {
/* export functions (and leave namespace table on top of stack) */
#if LUA_VERSION_NUM > 501 && !defined(LUA_COMPAT_MODULE)
lua_newtable(L);
luaL_setfuncs(L, func, 0);
#else
luaL_openlib(L, "socket", func, 0);
#endif
#ifdef LUASOCKET_DEBUG
lua_pushstring(L, "_DEBUG");
lua_pushboolean(L, 1);