diff options
Diffstat (limited to '')
-rw-r--r-- | src/compat.cpp (renamed from src/compat.c) | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/src/compat.c b/src/compat.cpp index bc39d4c..73d0f6b 100644 --- a/src/compat.c +++ b/src/compat.cpp | |||
@@ -14,7 +14,8 @@ | |||
14 | #if LUA_VERSION_NUM == 501 | 14 | #if LUA_VERSION_NUM == 501 |
15 | // ################################################################################################ | 15 | // ################################################################################################ |
16 | // ################################################################################################ | 16 | // ################################################################################################ |
17 | static int luaL_getsubtable (lua_State *L, int idx, const char *fname) | 17 | |
18 | static int luaL_getsubtable(lua_State* L, int idx, const char* fname) | ||
18 | { | 19 | { |
19 | lua_getfield(L, idx, fname); | 20 | lua_getfield(L, idx, fname); |
20 | if (lua_istable(L, -1)) | 21 | if (lua_istable(L, -1)) |
@@ -32,7 +33,7 @@ static int luaL_getsubtable (lua_State *L, int idx, const char *fname) | |||
32 | 33 | ||
33 | // ################################################################################################ | 34 | // ################################################################################################ |
34 | 35 | ||
35 | 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) |
36 | { | 37 | { |
37 | lua_pushcfunction(L, openf); | 38 | lua_pushcfunction(L, openf); |
38 | lua_pushstring(L, modname); /* argument to open function */ | 39 | lua_pushstring(L, modname); /* argument to open function */ |
@@ -58,21 +59,21 @@ void luaL_requiref (lua_State *L, const char *modname, lua_CFunction openf, int | |||
58 | void* lua_newuserdatauv( lua_State* L, size_t sz, int nuvalue) | 59 | void* lua_newuserdatauv( lua_State* L, size_t sz, int nuvalue) |
59 | { | 60 | { |
60 | ASSERT_L( nuvalue <= 1); | 61 | ASSERT_L( nuvalue <= 1); |
61 | return lua_newuserdata( L, sz); | 62 | return lua_newuserdata(L, sz); |
62 | } | 63 | } |
63 | 64 | ||
64 | // ################################################################################################ | 65 | // ################################################################################################ |
65 | 66 | ||
66 | // push on stack uservalue #n of full userdata at idx | 67 | // push on stack uservalue #n of full userdata at idx |
67 | int lua_getiuservalue( lua_State* L, int idx, int n) | 68 | int lua_getiuservalue(lua_State* L, int idx, int n) |
68 | { | 69 | { |
69 | // full userdata can have only 1 uservalue before 5.4 | 70 | // full userdata can have only 1 uservalue before 5.4 |
70 | if( n > 1) | 71 | if( n > 1) |
71 | { | 72 | { |
72 | lua_pushnil( L); | 73 | lua_pushnil(L); |
73 | return LUA_TNONE; | 74 | return LUA_TNONE; |
74 | } | 75 | } |
75 | lua_getuservalue( L, idx); | 76 | lua_getuservalue(L, idx); |
76 | 77 | ||
77 | #if LUA_VERSION_NUM == 501 | 78 | #if LUA_VERSION_NUM == 501 |
78 | /* default environment is not a nil (see lua_getfenv) */ | 79 | /* default environment is not a nil (see lua_getfenv) */ |
@@ -80,33 +81,33 @@ int lua_getiuservalue( lua_State* L, int idx, int n) | |||
80 | 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)) |
81 | { | 82 | { |
82 | lua_pop(L, 2); | 83 | lua_pop(L, 2); |
83 | lua_pushnil( L); | 84 | lua_pushnil(L); |
84 | 85 | ||
85 | return LUA_TNONE; | 86 | return LUA_TNONE; |
86 | } | 87 | } |
87 | lua_pop(L, 1); /* remove package */ | 88 | lua_pop(L, 1); /* remove package */ |
88 | #endif | 89 | #endif |
89 | 90 | ||
90 | return lua_type( L, -1); | 91 | return lua_type(L, -1); |
91 | } | 92 | } |
92 | 93 | ||
93 | // ################################################################################################ | 94 | // ################################################################################################ |
94 | 95 | ||
95 | // Pops a value from the stack and sets it as the new n-th user value associated to the full userdata at the given index. | 96 | // Pops a value from the stack and sets it as the new n-th user value associated to the full userdata at the given index. |
96 | // Returns 0 if the userdata does not have that value. | 97 | // Returns 0 if the userdata does not have that value. |
97 | int lua_setiuservalue( lua_State* L, int idx, int n) | 98 | int lua_setiuservalue(lua_State* L, int idx, int n) |
98 | { | 99 | { |
99 | if( n > 1 | 100 | if( n > 1 |
100 | #if LUA_VERSION_NUM == 501 | 101 | #if LUA_VERSION_NUM == 501 |
101 | || lua_type( L, -1) != LUA_TTABLE | 102 | || lua_type(L, -1) != LUA_TTABLE |
102 | #endif | 103 | #endif |
103 | ) | 104 | ) |
104 | { | 105 | { |
105 | lua_pop( L, 1); | 106 | lua_pop(L, 1); |
106 | return 0; | 107 | return 0; |
107 | } | 108 | } |
108 | 109 | ||
109 | (void) lua_setuservalue( L, idx); | 110 | lua_setuservalue(L, idx); |
110 | return 1; // I guess anything non-0 is ok | 111 | return 1; // I guess anything non-0 is ok |
111 | } | 112 | } |
112 | 113 | ||