aboutsummaryrefslogtreecommitdiff
path: root/src/compat.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/compat.c')
-rw-r--r--src/compat.c102
1 files changed, 51 insertions, 51 deletions
diff --git a/src/compat.c b/src/compat.c
index d9bc3dd..19159a9 100644
--- a/src/compat.c
+++ b/src/compat.c
@@ -12,34 +12,34 @@
12#if LUA_VERSION_NUM == 501 12#if LUA_VERSION_NUM == 501
13static int luaL_getsubtable (lua_State *L, int idx, const char *fname) 13static int luaL_getsubtable (lua_State *L, int idx, const char *fname)
14{ 14{
15 lua_getfield(L, idx, fname); 15 lua_getfield(L, idx, fname);
16 if (lua_istable(L, -1)) 16 if (lua_istable(L, -1))
17 return 1; /* table already there */ 17 return 1; /* table already there */
18 else 18 else
19 { 19 {
20 lua_pop(L, 1); /* remove previous result */ 20 lua_pop(L, 1); /* remove previous result */
21 idx = lua_absindex(L, idx); 21 idx = lua_absindex(L, idx);
22 lua_newtable(L); 22 lua_newtable(L);
23 lua_pushvalue(L, -1); /* copy to be left at top */ 23 lua_pushvalue(L, -1); /* copy to be left at top */
24 lua_setfield(L, idx, fname); /* assign new table to field */ 24 lua_setfield(L, idx, fname); /* assign new table to field */
25 return 0; /* false, because did not find table there */ 25 return 0; /* false, because did not find table there */
26 } 26 }
27} 27}
28 28
29void luaL_requiref (lua_State *L, const char *modname, lua_CFunction openf, int glb) 29void luaL_requiref (lua_State *L, const char *modname, lua_CFunction openf, int glb)
30{ 30{
31 lua_pushcfunction(L, openf); 31 lua_pushcfunction(L, openf);
32 lua_pushstring(L, modname); /* argument to open function */ 32 lua_pushstring(L, modname); /* argument to open function */
33 lua_call(L, 1, 1); /* open module */ 33 lua_call(L, 1, 1); /* open module */
34 luaL_getsubtable(L, LUA_REGISTRYINDEX, LUA_LOADED_TABLE); 34 luaL_getsubtable(L, LUA_REGISTRYINDEX, LUA_LOADED_TABLE);
35 lua_pushvalue(L, -2); /* make copy of module (call result) */ 35 lua_pushvalue(L, -2); /* make copy of module (call result) */
36 lua_setfield(L, -2, modname); /* _LOADED[modname] = module */ 36 lua_setfield(L, -2, modname); /* _LOADED[modname] = module */
37 lua_pop(L, 1); /* remove _LOADED table */ 37 lua_pop(L, 1); /* remove _LOADED table */
38 if (glb) 38 if (glb)
39 { 39 {
40 lua_pushvalue(L, -1); /* copy of 'mod' */ 40 lua_pushvalue(L, -1); /* copy of 'mod' */
41 lua_setglobal(L, modname); /* _G[modname] = module */ 41 lua_setglobal(L, modname); /* _G[modname] = module */
42 } 42 }
43} 43}
44#endif // LUA_VERSION_NUM 44#endif // LUA_VERSION_NUM
45 45
@@ -47,49 +47,49 @@ void luaL_requiref (lua_State *L, const char *modname, lua_CFunction openf, int
47 47
48void* lua_newuserdatauv( lua_State* L, size_t sz, int nuvalue) 48void* lua_newuserdatauv( lua_State* L, size_t sz, int nuvalue)
49{ 49{
50 ASSERT_L( nuvalue <= 1); 50 ASSERT_L( nuvalue <= 1);
51 return lua_newuserdata( L, sz); 51 return lua_newuserdata( L, sz);
52} 52}
53 53
54int lua_getiuservalue( lua_State* L, int idx, int n) 54int lua_getiuservalue( lua_State* L, int idx, int n)
55{ 55{
56 if( n > 1) 56 if( n > 1)
57 { 57 {
58 lua_pushnil( L); 58 lua_pushnil( L);
59 return LUA_TNONE; 59 return LUA_TNONE;
60 } 60 }
61 lua_getuservalue( L, idx); 61 lua_getuservalue( L, idx);
62 62
63#if LUA_VERSION_NUM == 501 63#if LUA_VERSION_NUM == 501
64 /* default environment is not a nil (see lua_getfenv) */ 64 /* default environment is not a nil (see lua_getfenv) */
65 lua_getglobal(L, "package"); 65 lua_getglobal(L, "package");
66 if (lua_rawequal(L, -2, -1) || lua_rawequal(L, -2, LUA_GLOBALSINDEX)) 66 if (lua_rawequal(L, -2, -1) || lua_rawequal(L, -2, LUA_GLOBALSINDEX))
67 { 67 {
68 lua_pop(L, 2); 68 lua_pop(L, 2);
69 lua_pushnil( L); 69 lua_pushnil( L);
70 70
71 return LUA_TNONE; 71 return LUA_TNONE;
72 } 72 }
73 lua_pop(L, 1); /* remove package */ 73 lua_pop(L, 1); /* remove package */
74#endif 74#endif
75 75
76 return lua_type( L, -1); 76 return lua_type( L, -1);
77} 77}
78 78
79int lua_setiuservalue( lua_State* L, int idx, int n) 79int lua_setiuservalue( lua_State* L, int idx, int n)
80{ 80{
81 if( n > 1 81 if( n > 1
82#if LUA_VERSION_NUM == 501 82#if LUA_VERSION_NUM == 501
83 || lua_type( L, -1) != LUA_TTABLE 83 || lua_type( L, -1) != LUA_TTABLE
84#endif 84#endif
85 ) 85 )
86 { 86 {
87 lua_pop( L, 1); 87 lua_pop( L, 1);
88 return 0; 88 return 0;
89 } 89 }
90 90
91 (void) lua_setuservalue( L, idx); 91 (void) lua_setuservalue( L, idx);
92 return 1; // I guess anything non-0 is ok 92 return 1; // I guess anything non-0 is ok
93} 93}
94 94
95#endif // LUA_VERSION_NUM 95#endif // LUA_VERSION_NUM