Skip to content

Commit ed096dc

Browse files
Msam-github
authored andcommitted
Compiles with lua5.2 even without LUA_COMPAT
Also keep global namespace clean when compiled against lua5.2
1 parent 5b91e48 commit ed096dc

File tree

7 files changed

+24
-6
lines changed

7 files changed

+24
-6
lines changed

netutil.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
require"pcap"
1+
local pcap = require"pcap"
22
require"net"
33
require"tostring"
44

pcap-dump

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env lua5.1
22

3-
require"pcap"
3+
local pcap = require"pcap"
44

55
arg.device = "any"
66
arg.snaplen = 0

pcap-recode

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env lua
22

3-
require"pcapx"
3+
local pcap = require"pcapx"
44

55
pcap.recode(arg[1], arg[2])
66

pcap-split

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env lua5.1
22

3-
require"pcap"
3+
local pcap = require"pcap"
44

55
file = assert(arg[1])
66
cap = assert(pcap.open_offline(file))

pcap-test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env lua5.1
22

3-
require "pcap"
3+
local pcap = require "pcap"
44
require "netutil"
55

66
local function gc()

pcap.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ THE POSSIBILITY OF SUCH DAMAGE.
4747
#include <wt-win-common.h>
4848
#endif
4949

50+
#if LUA_VERSION_NUM > 501
51+
#define luaL_reg luaL_Reg
52+
#endif
53+
5054
static double tv2secs(struct timeval* tv)
5155
{
5256
double secs = tv->tv_sec;
@@ -94,7 +98,13 @@ static void v_obj_metatable(lua_State* L, const char* regid, const struct luaL_r
9498
{
9599
/* metatable = { ... methods ... } */
96100
luaL_newmetatable(L, regid);
101+
102+
#if LUA_VERSION_NUM > 501
103+
luaL_setfuncs(L, methods, 0);
104+
#else
97105
luaL_register(L, NULL, methods);
106+
#endif
107+
98108
/* metatable["__index"] = metatable */
99109
lua_pushvalue(L, -1);
100110
lua_setfield(L, -2, "__index");
@@ -698,7 +708,14 @@ int luaopen_pcap (lua_State *L)
698708
{
699709
v_obj_metatable(L, L_PCAP_DUMPER_REGID, dumper_methods);
700710
v_obj_metatable(L, L_PCAP_REGID, pcap_methods);
711+
712+
#if LUA_VERSION_NUM > 501
713+
lua_newtable(L);
714+
luaL_setfuncs (L,pcap_module,0); //leaving global namespace clean in 5.2
715+
#else
701716
luaL_register(L, "pcap", pcap_module);
717+
#endif
718+
702719
lua_pushstring(L, pcap_lib_version());
703720
lua_setfield(L, -2, "_LIB_VERSION");
704721

pcapx.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ pcapx - extensions to pcap
33
44
]]
55

6-
require"pcap"
6+
local pcap = require"pcap"
77
require"net"
88

99
local function NOP()
@@ -50,3 +50,4 @@ function pcap.recode(incap, outcap, progress, debug)
5050
return outcap
5151
end
5252

53+
return pcap

0 commit comments

Comments
 (0)