diff options
Diffstat (limited to 'src/compat.cpp')
-rw-r--r-- | src/compat.cpp | 35 |
1 files changed, 25 insertions, 10 deletions
diff --git a/src/compat.cpp b/src/compat.cpp index 47fe37e..8acab25 100644 --- a/src/compat.cpp +++ b/src/compat.cpp | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | * ############################################################################################### | 2 | * ############################################################################################### |
3 | * ######################################### Lua 5.1/5.2 ######################################### | 3 | * ####################################### Lua 5.1/5.2/5.3 ####################################### |
4 | * ############################################################################################### | 4 | * ############################################################################################### |
5 | */ | 5 | */ |
6 | #include "compat.h" | 6 | #include "compat.h" |
@@ -9,7 +9,12 @@ | |||
9 | /* | 9 | /* |
10 | ** Copied from Lua 5.2 loadlib.c | 10 | ** Copied from Lua 5.2 loadlib.c |
11 | */ | 11 | */ |
12 | // ################################################################################################ | ||
13 | // ################################################################################################ | ||
12 | #if LUA_VERSION_NUM == 501 | 14 | #if LUA_VERSION_NUM == 501 |
15 | // ################################################################################################ | ||
16 | // ################################################################################################ | ||
17 | |||
13 | static int luaL_getsubtable (lua_State *L, int idx, const char *fname) | 18 | static int luaL_getsubtable (lua_State *L, int idx, const char *fname) |
14 | { | 19 | { |
15 | lua_getfield(L, idx, fname); | 20 | lua_getfield(L, idx, fname); |
@@ -26,6 +31,8 @@ static int luaL_getsubtable (lua_State *L, int idx, const char *fname) | |||
26 | } | 31 | } |
27 | } | 32 | } |
28 | 33 | ||
34 | // ################################################################################################ | ||
35 | |||
29 | void luaL_requiref (lua_State *L, const char *modname, lua_CFunction openf, int glb) | 36 | void luaL_requiref (lua_State *L, const char *modname, lua_CFunction openf, int glb) |
30 | { | 37 | { |
31 | lua_pushcfunction(L, openf); | 38 | lua_pushcfunction(L, openf); |
@@ -43,24 +50,30 @@ void luaL_requiref (lua_State *L, const char *modname, lua_CFunction openf, int | |||
43 | } | 50 | } |
44 | #endif // LUA_VERSION_NUM | 51 | #endif // LUA_VERSION_NUM |
45 | 52 | ||
53 | // ################################################################################################ | ||
54 | // ################################################################################################ | ||
46 | #if LUA_VERSION_NUM < 504 | 55 | #if LUA_VERSION_NUM < 504 |
56 | // ################################################################################################ | ||
57 | // ################################################################################################ | ||
47 | 58 | ||
48 | void* lua_newuserdatauv( lua_State* L, size_t sz, int nuvalue) | 59 | void* lua_newuserdatauv( lua_State* L, size_t sz, int nuvalue) |
49 | { | 60 | { |
50 | ASSERT_L( nuvalue <= 1); | 61 | ASSERT_L( nuvalue <= 1); |
51 | return lua_newuserdata( L, sz); | 62 | return lua_newuserdata(L, sz); |
52 | } | 63 | } |
53 | 64 | ||
65 | // ################################################################################################ | ||
66 | |||
54 | // push on stack uservalue #n of full userdata at idx | 67 | // push on stack uservalue #n of full userdata at idx |
55 | int lua_getiuservalue(lua_State* L, int idx, int n) | 68 | int lua_getiuservalue(lua_State* L, int idx, int n) |
56 | { | 69 | { |
57 | // full userdata can have only 1 uservalue before 5.4 | 70 | // full userdata can have only 1 uservalue before 5.4 |
58 | if( n > 1) | 71 | if( n > 1) |
59 | { | 72 | { |
60 | lua_pushnil( L); | 73 | lua_pushnil(L); |
61 | return LUA_TNONE; | 74 | return LUA_TNONE; |
62 | } | 75 | } |
63 | lua_getuservalue( L, idx); | 76 | lua_getuservalue(L, idx); |
64 | 77 | ||
65 | #if LUA_VERSION_NUM == 501 | 78 | #if LUA_VERSION_NUM == 501 |
66 | /* default environment is not a nil (see lua_getfenv) */ | 79 | /* default environment is not a nil (see lua_getfenv) */ |
@@ -68,30 +81,32 @@ int lua_getiuservalue(lua_State* L, int idx, int n) | |||
68 | if (lua_rawequal(L, -2, -1) || lua_rawequal(L, -2, LUA_GLOBALSINDEX)) | 81 | if (lua_rawequal(L, -2, -1) || lua_rawequal(L, -2, LUA_GLOBALSINDEX)) |
69 | { | 82 | { |
70 | lua_pop(L, 2); | 83 | lua_pop(L, 2); |
71 | lua_pushnil( L); | 84 | lua_pushnil(L); |
72 | 85 | ||
73 | return LUA_TNONE; | 86 | return LUA_TNONE; |
74 | } | 87 | } |
75 | lua_pop(L, 1); /* remove package */ | 88 | lua_pop(L, 1); /* remove package */ |
76 | #endif | 89 | #endif |
77 | 90 | ||
78 | return lua_type( L, -1); | 91 | return lua_type(L, -1); |
79 | } | 92 | } |
80 | 93 | ||
94 | // ################################################################################################ | ||
95 | |||
81 | // pop stack top, sets it a uservalue #n of full userdata at idx | 96 | // pop stack top, sets it a uservalue #n of full userdata at idx |
82 | int lua_setiuservalue( lua_State* L, int idx, int n) | 97 | int lua_setiuservalue(lua_State* L, int idx, int n) |
83 | { | 98 | { |
84 | if( n > 1 | 99 | if( n > 1 |
85 | #if LUA_VERSION_NUM == 501 | 100 | #if LUA_VERSION_NUM == 501 |
86 | || lua_type( L, -1) != LUA_TTABLE | 101 | || lua_type(L, -1) != LUA_TTABLE |
87 | #endif | 102 | #endif |
88 | ) | 103 | ) |
89 | { | 104 | { |
90 | lua_pop( L, 1); | 105 | lua_pop(L, 1); |
91 | return 0; | 106 | return 0; |
92 | } | 107 | } |
93 | 108 | ||
94 | (void) lua_setuservalue( L, idx); | 109 | std::ignore = lua_setuservalue(L, idx); |
95 | return 1; // I guess anything non-0 is ok | 110 | return 1; // I guess anything non-0 is ok |
96 | } | 111 | } |
97 | 112 | ||