Project

General

Profile

patch-src_mod__magnet.c

pkubaj, 2015-09-29 10:01

 
1
--- src/mod_magnet.c.orig        2015-08-29 14:22:38.000000000 +0200
2
+++ src/mod_magnet.c        2015-09-29 11:46:30.312599419 +0200
3
@@ -24,6 +24,10 @@
4
 #define MAGNET_CONFIG_PHYSICAL_PATH "magnet.attract-physical-path-to"
5
 #define MAGNET_RESTART_REQUEST      99
6
 
7
+#if LUA_VERSION_NUM >= 502
8
+#define LUA_GLOBALSINDEX LUA_REGISTRYINDEX
9
+#endif
10
+
11
 /* plugin config for all request/connections */
12
 
13
 static jmp_buf exceptionjmp;
14
@@ -688,7 +692,11 @@
15
          * get the environment of the function
16
          */
17
 
18
+#if LUA_VERSION_NUM >= 502
19
+        lua_getuservalue(L, -1); /* -1 is the function */
20
+#else
21
         lua_getfenv(L, -1); /* -1 is the function */
22
+#endif
23
 
24
         /* lighty.header */
25
 
26
@@ -738,7 +746,11 @@
27
          */
28
 
29
         force_assert(lua_isfunction(L, -1));
30
+#if LUA_VERSION_NUM >= 502
31
+        lua_getuservalue(L, -1); /* -1 is the function */
32
+#else
33
         lua_getfenv(L, -1); /* -1 is the function */
34
+#endif
35
 
36
         lua_getfield(L, -1, "lighty"); /* lighty.* from the env  */
37
         force_assert(lua_istable(L, -1));
38
@@ -988,7 +1000,11 @@
39
         lua_setmetatable(L, -2); /* setmetatable({}, {__index = _G}) (sp -= 1) */
40
 
41
 
42
+#if LUA_VERSION_NUM >= 502
43
+        lua_setuservalue(L, -2); /* on the stack should be a modified env (sp -= 1) */
44
+#else
45
         lua_setfenv(L, -2); /* on the stack should be a modified env (sp -= 1) */
46
+#endif
47
 
48
         errfunc = push_traceback(L, 0);
49
         if (lua_pcall(L, 0, 1, errfunc)) {