Build with Lua 5.2 without LUA_COMPAT_MODULE flag.

LUASOCKET_USE_GLOBAL flag enable create global variables when load socket/mime modules.
This commit is contained in:
moteus 2013-05-27 12:45:09 +04:00
parent bd51d8c1a5
commit 920bc97629
14 changed files with 179 additions and 115 deletions

View file

@ -18,9 +18,6 @@
#include "lua.h"
#include "lauxlib.h"
#if !defined(LUA_VERSION_NUM) || (LUA_VERSION_NUM < 501)
#include "compat-5.1.h"
#endif
/*=========================================================================*\
* LuaSocket includes
@ -81,6 +78,34 @@ static int global_unload(lua_State *L) {
return 0;
}
#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
/*-------------------------------------------------------------------------*\
* Setup basic stuff.
\*-------------------------------------------------------------------------*/