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 | |
parent | 5167ddaf499cf198b10208a2f76c27629e99ae1b (diff) | |
download | luasocket-79e6c4915d267e149e1f3b134901bf355d439c15.tar.gz luasocket-79e6c4915d267e149e1f3b134901bf355d439c15.tar.bz2 luasocket-79e6c4915d267e149e1f3b134901bf355d439c15.zip |
Export global only if LUA_COMPAT_MODULE defined.
-rw-r--r-- | src/except.c | 4 | ||||
-rw-r--r-- | src/inet.c | 4 | ||||
-rw-r--r-- | src/luasocket.c | 25 | ||||
-rw-r--r-- | src/makefile | 12 | ||||
-rw-r--r-- | src/mime.c | 8 | ||||
-rw-r--r-- | src/select.c | 4 | ||||
-rw-r--r-- | src/serial.c | 12 | ||||
-rw-r--r-- | src/tcp.c | 4 | ||||
-rw-r--r-- | src/timeout.c | 4 | ||||
-rw-r--r-- | src/udp.c | 4 | ||||
-rw-r--r-- | src/unix.c | 11 |
11 files changed, 55 insertions, 37 deletions
diff --git a/src/except.c b/src/except.c index 1d1ade0..002e701 100644 --- a/src/except.c +++ b/src/except.c | |||
@@ -92,6 +92,10 @@ static int global_protect(lua_State *L) { | |||
92 | * Init module | 92 | * Init module |
93 | \*-------------------------------------------------------------------------*/ | 93 | \*-------------------------------------------------------------------------*/ |
94 | int except_open(lua_State *L) { | 94 | int except_open(lua_State *L) { |
95 | #if LUA_VERSION_NUM > 501 && !defined(LUA_COMPAT_MODULE) | ||
96 | luaL_setfuncs(L, func, 0); | ||
97 | #else | ||
95 | luaL_openlib(L, NULL, func, 0); | 98 | luaL_openlib(L, NULL, func, 0); |
99 | #endif | ||
96 | return 0; | 100 | return 0; |
97 | } | 101 | } |
@@ -40,7 +40,11 @@ int inet_open(lua_State *L) | |||
40 | { | 40 | { |
41 | lua_pushstring(L, "dns"); | 41 | lua_pushstring(L, "dns"); |
42 | lua_newtable(L); | 42 | lua_newtable(L); |
43 | #if LUA_VERSION_NUM > 501 && !defined(LUA_COMPAT_MODULE) | ||
44 | luaL_setfuncs(L, func, 0); | ||
45 | #else | ||
43 | luaL_openlib(L, NULL, func, 0); | 46 | luaL_openlib(L, NULL, func, 0); |
47 | #endif | ||
44 | lua_settable(L, -3); | 48 | lua_settable(L, -3); |
45 | return 0; | 49 | return 0; |
46 | } | 50 | } |
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); |
diff --git a/src/makefile b/src/makefile index 94a2f9f..42589f6 100644 --- a/src/makefile +++ b/src/makefile | |||
@@ -25,6 +25,10 @@ LUAV?=5.1 | |||
25 | # for testing and debugging luasocket itself | 25 | # for testing and debugging luasocket itself |
26 | DEBUG?=NODEBUG | 26 | DEBUG?=NODEBUG |
27 | 27 | ||
28 | # COMPAT: COMPAT NOCOMPAT | ||
29 | # when compiling for 5.2, use LUA_COMPAT_MODULE | ||
30 | COMPAT?=NOCOMPAT | ||
31 | |||
28 | # where lua headers are found for macosx builds | 32 | # where lua headers are found for macosx builds |
29 | # LUAINC_macosx: | 33 | # LUAINC_macosx: |
30 | # /opt/local/include | 34 | # /opt/local/include |
@@ -125,7 +129,7 @@ PLATS= macosx linux win32 mingw | |||
125 | SO_macosx=so | 129 | SO_macosx=so |
126 | O_macosx=o | 130 | O_macosx=o |
127 | CC_macosx=gcc | 131 | CC_macosx=gcc |
128 | DEF_macosx= -DLUASOCKET_$(DEBUG) -DUNIX_HAS_SUN_LEN -DLUA_COMPAT_MODULE \ | 132 | DEF_macosx= -DLUASOCKET_$(DEBUG) -DUNIX_HAS_SUN_LEN -DLUA_$(COMPAT)_MODULE \ |
129 | -DLUASOCKET_API='__attribute__((visibility("default")))' \ | 133 | -DLUASOCKET_API='__attribute__((visibility("default")))' \ |
130 | -DMIME_API='__attribute__((visibility("default")))' | 134 | -DMIME_API='__attribute__((visibility("default")))' |
131 | CFLAGS_macosx= -I$(LUAINC) $(DEF) -pedantic -Wall -O2 -fno-common \ | 135 | CFLAGS_macosx= -I$(LUAINC) $(DEF) -pedantic -Wall -O2 -fno-common \ |
@@ -140,7 +144,7 @@ SOCKET_macosx=usocket.o | |||
140 | SO_linux=so | 144 | SO_linux=so |
141 | O_linux=o | 145 | O_linux=o |
142 | CC_linux=gcc | 146 | CC_linux=gcc |
143 | DEF_linux=-DLUASOCKET_$(DEBUG) -DLUA_COMPAT_MODULE \ | 147 | DEF_linux=-DLUASOCKET_$(DEBUG) -DLUA_$(COMPAT)_MODULE \ |
144 | -DLUASOCKET_API='__attribute__((visibility("default")))' \ | 148 | -DLUASOCKET_API='__attribute__((visibility("default")))' \ |
145 | -DMIME_API='__attribute__((visibility("default")))' | 149 | -DMIME_API='__attribute__((visibility("default")))' |
146 | CFLAGS_linux= -I$(LUAINC) $(DEF) -pedantic -Wall -Wshadow -Wextra \ | 150 | CFLAGS_linux= -I$(LUAINC) $(DEF) -pedantic -Wall -Wshadow -Wextra \ |
@@ -155,7 +159,7 @@ SOCKET_linux=usocket.o | |||
155 | SO_mingw=dll | 159 | SO_mingw=dll |
156 | O_mingw=o | 160 | O_mingw=o |
157 | CC_mingw=gcc | 161 | CC_mingw=gcc |
158 | DEF_mingw= -DLUASOCKET_INET_PTON -DLUASOCKET_$(DEBUG) -DLUA_COMPAT_MODULE \ | 162 | DEF_mingw= -DLUASOCKET_INET_PTON -DLUASOCKET_$(DEBUG) -DLUA_$(COMPAT)_MODULE \ |
159 | -DWINVER=0x0501 -DLUASOCKET_API='__declspec(dllexport)' \ | 163 | -DWINVER=0x0501 -DLUASOCKET_API='__declspec(dllexport)' \ |
160 | -DMIME_API='__declspec(dllexport)' | 164 | -DMIME_API='__declspec(dllexport)' |
161 | CFLAGS_mingw= -I$(LUAINC) $(DEF) -pedantic -Wall -O2 -fno-common \ | 165 | CFLAGS_mingw= -I$(LUAINC) $(DEF) -pedantic -Wall -O2 -fno-common \ |
@@ -173,7 +177,7 @@ O_win32=obj | |||
173 | CC_win32=cl | 177 | CC_win32=cl |
174 | DEF_win32= //D "WIN32" //D "NDEBUG" //D "_WINDOWS" //D "_USRDLL" \ | 178 | DEF_win32= //D "WIN32" //D "NDEBUG" //D "_WINDOWS" //D "_USRDLL" \ |
175 | //D "LUASOCKET_API=__declspec(dllexport)" //D "_CRT_SECURE_NO_WARNINGS" \ | 179 | //D "LUASOCKET_API=__declspec(dllexport)" //D "_CRT_SECURE_NO_WARNINGS" \ |
176 | //D "_WINDLL" //D "LUA_COMPAT_MODULE" \ | 180 | //D "_WINDLL" //D "LUA_$(COMPAT)_MODULE" \ |
177 | //D "MIME_API=__declspec(dllexport)" \ | 181 | //D "MIME_API=__declspec(dllexport)" \ |
178 | //D "LUASOCKET_$(DEBUG)" | 182 | //D "LUASOCKET_$(DEBUG)" |
179 | CFLAGS_win32=//I "$(LUAINC)" $(DEF) //O2 //Ot //MD //W3 //nologo | 183 | CFLAGS_win32=//I "$(LUAINC)" $(DEF) //O2 //Ot //MD //W3 //nologo |
@@ -81,13 +81,9 @@ static UC b64unbase[256]; | |||
81 | \*-------------------------------------------------------------------------*/ | 81 | \*-------------------------------------------------------------------------*/ |
82 | MIME_API int luaopen_mime_core(lua_State *L) | 82 | MIME_API int luaopen_mime_core(lua_State *L) |
83 | { | 83 | { |
84 | #if LUA_VERSION_NUM > 501 | 84 | #if LUA_VERSION_NUM > 501 && !defined(LUA_COMPAT_MODULE) |
85 | lua_newtable(L); | 85 | lua_newtable(L); |
86 | #ifdef LUASOCKET_USE_GLOBAL | 86 | luaL_setfuncs(L, func, 0); |
87 | lua_setglobal(L,"mime"); | ||
88 | lua_getglobal(L,"mime"); | ||
89 | #endif | ||
90 | luaL_setfuncs(L,func,0); | ||
91 | #else | 87 | #else |
92 | luaL_openlib(L, "mime", func, 0); | 88 | luaL_openlib(L, "mime", func, 0); |
93 | #endif | 89 | #endif |
diff --git a/src/select.c b/src/select.c index 51fb198..fafaa62 100644 --- a/src/select.c +++ b/src/select.c | |||
@@ -40,7 +40,11 @@ int select_open(lua_State *L) { | |||
40 | lua_pushstring(L, "_SETSIZE"); | 40 | lua_pushstring(L, "_SETSIZE"); |
41 | lua_pushnumber(L, FD_SETSIZE); | 41 | lua_pushnumber(L, FD_SETSIZE); |
42 | lua_rawset(L, -3); | 42 | lua_rawset(L, -3); |
43 | #if LUA_VERSION_NUM > 501 && !defined(LUA_COMPAT_MODULE) | ||
44 | luaL_setfuncs(L, func, 0); | ||
45 | #else | ||
43 | luaL_openlib(L, NULL, func, 0); | 46 | luaL_openlib(L, NULL, func, 0); |
47 | #endif | ||
44 | return 0; | 48 | return 0; |
45 | } | 49 | } |
46 | 50 | ||
diff --git a/src/serial.c b/src/serial.c index 5b09e76..66e8da6 100644 --- a/src/serial.c +++ b/src/serial.c | |||
@@ -55,6 +55,8 @@ static luaL_Reg serial_methods[] = { | |||
55 | }; | 55 | }; |
56 | 56 | ||
57 | /* our socket creation function */ | 57 | /* our socket creation function */ |
58 | /* this is an ad-hoc module that returns a single function | ||
59 | * as such, do not include other functions in this array. */ | ||
58 | static luaL_Reg func[] = { | 60 | static luaL_Reg func[] = { |
59 | {"serial", global_create}, | 61 | {"serial", global_create}, |
60 | {NULL, NULL} | 62 | {NULL, NULL} |
@@ -69,11 +71,13 @@ LUASOCKET_API int luaopen_socket_serial(lua_State *L) { | |||
69 | auxiliar_newclass(L, "serial{client}", serial_methods); | 71 | auxiliar_newclass(L, "serial{client}", serial_methods); |
70 | /* create class groups */ | 72 | /* create class groups */ |
71 | auxiliar_add2group(L, "serial{client}", "serial{any}"); | 73 | auxiliar_add2group(L, "serial{client}", "serial{any}"); |
72 | /* make sure the function ends up in the package table */ | 74 | #if LUA_VERSION_NUM > 501 && !defined(LUA_COMPAT_MODULE) |
75 | lua_pushcfunction(L, global_create); | ||
76 | #else | ||
77 | /* set function into socket namespace */ | ||
73 | luaL_openlib(L, "socket", func, 0); | 78 | luaL_openlib(L, "socket", func, 0); |
74 | /* return the function instead of the 'socket' table */ | 79 | lua_pushcfunction(L, global_create); |
75 | lua_pushstring(L, "serial"); | 80 | #endif |
76 | lua_gettable(L, -2); | ||
77 | return 1; | 81 | return 1; |
78 | } | 82 | } |
79 | 83 | ||
@@ -107,7 +107,11 @@ int tcp_open(lua_State *L) | |||
107 | auxiliar_add2group(L, "tcp{client}", "tcp{any}"); | 107 | auxiliar_add2group(L, "tcp{client}", "tcp{any}"); |
108 | auxiliar_add2group(L, "tcp{server}", "tcp{any}"); | 108 | auxiliar_add2group(L, "tcp{server}", "tcp{any}"); |
109 | /* define library functions */ | 109 | /* define library functions */ |
110 | #if LUA_VERSION_NUM > 501 && !defined(LUA_COMPAT_MODULE) | ||
111 | luaL_setfuncs(L, func, 0); | ||
112 | #else | ||
110 | luaL_openlib(L, NULL, func, 0); | 113 | luaL_openlib(L, NULL, func, 0); |
114 | #endif | ||
111 | return 0; | 115 | return 0; |
112 | } | 116 | } |
113 | 117 | ||
diff --git a/src/timeout.c b/src/timeout.c index c7354b5..bdd5e1c 100644 --- a/src/timeout.c +++ b/src/timeout.c | |||
@@ -144,7 +144,11 @@ double timeout_gettime(void) { | |||
144 | * Initializes module | 144 | * Initializes module |
145 | \*-------------------------------------------------------------------------*/ | 145 | \*-------------------------------------------------------------------------*/ |
146 | int timeout_open(lua_State *L) { | 146 | int timeout_open(lua_State *L) { |
147 | #if LUA_VERSION_NUM > 501 && !defined(LUA_COMPAT_MODULE) | ||
148 | luaL_setfuncs(L, func, 0); | ||
149 | #else | ||
147 | luaL_openlib(L, NULL, func, 0); | 150 | luaL_openlib(L, NULL, func, 0); |
151 | #endif | ||
148 | return 0; | 152 | return 0; |
149 | } | 153 | } |
150 | 154 | ||
@@ -109,7 +109,11 @@ int udp_open(lua_State *L) | |||
109 | auxiliar_add2group(L, "udp{connected}", "select{able}"); | 109 | auxiliar_add2group(L, "udp{connected}", "select{able}"); |
110 | auxiliar_add2group(L, "udp{unconnected}", "select{able}"); | 110 | auxiliar_add2group(L, "udp{unconnected}", "select{able}"); |
111 | /* define library functions */ | 111 | /* define library functions */ |
112 | #if LUA_VERSION_NUM > 501 && !defined(LUA_COMPAT_MODULE) | ||
113 | luaL_setfuncs(L, func, 0); | ||
114 | #else | ||
112 | luaL_openlib(L, NULL, func, 0); | 115 | luaL_openlib(L, NULL, func, 0); |
116 | #endif | ||
113 | return 0; | 117 | return 0; |
114 | } | 118 | } |
115 | 119 | ||
@@ -69,6 +69,8 @@ static t_opt optset[] = { | |||
69 | }; | 69 | }; |
70 | 70 | ||
71 | /* our socket creation function */ | 71 | /* our socket creation function */ |
72 | /* this is an ad-hoc module that returns a single function | ||
73 | * as such, do not include other functions in this array. */ | ||
72 | static luaL_Reg func[] = { | 74 | static luaL_Reg func[] = { |
73 | {"unix", global_create}, | 75 | {"unix", global_create}, |
74 | {NULL, NULL} | 76 | {NULL, NULL} |
@@ -87,11 +89,14 @@ int luaopen_socket_unix(lua_State *L) { | |||
87 | auxiliar_add2group(L, "unix{master}", "unix{any}"); | 89 | auxiliar_add2group(L, "unix{master}", "unix{any}"); |
88 | auxiliar_add2group(L, "unix{client}", "unix{any}"); | 90 | auxiliar_add2group(L, "unix{client}", "unix{any}"); |
89 | auxiliar_add2group(L, "unix{server}", "unix{any}"); | 91 | auxiliar_add2group(L, "unix{server}", "unix{any}"); |
90 | /* make sure the function ends up in the package table */ | 92 | #if LUA_VERSION_NUM > 501 && !defined(LUA_COMPAT_MODULE) |
93 | lua_pushcfunction(L, global_create); | ||
94 | #else | ||
95 | /* set function into socket namespace */ | ||
91 | luaL_openlib(L, "socket", func, 0); | 96 | luaL_openlib(L, "socket", func, 0); |
97 | lua_pushcfunction(L, global_create); | ||
98 | #endif | ||
92 | /* return the function instead of the 'socket' table */ | 99 | /* return the function instead of the 'socket' table */ |
93 | lua_pushstring(L, "unix"); | ||
94 | lua_gettable(L, -2); | ||
95 | return 1; | 100 | return 1; |
96 | } | 101 | } |
97 | 102 | ||