diff options
author | Philipp Janda <siffiejoe@gmx.net> | 2016-07-08 11:04:19 +0200 |
---|---|---|
committer | Philipp Janda <siffiejoe@gmx.net> | 2016-07-08 11:04:19 +0200 |
commit | 8b2d71e601d1b9695aea084bb5bf7aa7dc0ca230 (patch) | |
tree | 5a98da37058475c0ca4c89916e03f81f83750d71 /c-api | |
parent | 80588ca126d2d115437c5ebc85284f4cc6dd512e (diff) | |
download | lua-compat-5.3-8b2d71e601d1b9695aea084bb5bf7aa7dc0ca230.tar.gz lua-compat-5.3-8b2d71e601d1b9695aea084bb5bf7aa7dc0ca230.tar.bz2 lua-compat-5.3-8b2d71e601d1b9695aea084bb5bf7aa7dc0ca230.zip |
Fix lua_len and luaL_len to use lua_Integer.
Diffstat (limited to 'c-api')
-rw-r--r-- | c-api/compat-5.3.c | 17 | ||||
-rw-r--r-- | c-api/compat-5.3.h | 2 |
2 files changed, 11 insertions, 8 deletions
diff --git a/c-api/compat-5.3.c b/c-api/compat-5.3.c index 4395bbc..d7d127f 100644 --- a/c-api/compat-5.3.c +++ b/c-api/compat-5.3.c | |||
@@ -100,10 +100,12 @@ COMPAT53_API void lua_copy (lua_State *L, int from, int to) { | |||
100 | 100 | ||
101 | COMPAT53_API void lua_len (lua_State *L, int i) { | 101 | COMPAT53_API void lua_len (lua_State *L, int i) { |
102 | switch (lua_type(L, i)) { | 102 | switch (lua_type(L, i)) { |
103 | case LUA_TSTRING: /* fall through */ | 103 | case LUA_TSTRING: |
104 | lua_pushnumber(L, (lua_Integer)lua_objlen(L, i)); | ||
105 | break; | ||
104 | case LUA_TTABLE: | 106 | case LUA_TTABLE: |
105 | if (!luaL_callmeta(L, i, "__len")) | 107 | if (!luaL_callmeta(L, i, "__len")) |
106 | lua_pushnumber(L, (int)lua_objlen(L, i)); | 108 | lua_pushnumber(L, (lua_Integer)lua_objlen(L, i)); |
107 | break; | 109 | break; |
108 | case LUA_TUSERDATA: | 110 | case LUA_TUSERDATA: |
109 | if (luaL_callmeta(L, i, "__len")) | 111 | if (luaL_callmeta(L, i, "__len")) |
@@ -136,7 +138,7 @@ COMPAT53_API lua_Integer lua_tointegerx (lua_State *L, int i, int *isnum) { | |||
136 | lua_Integer n = lua_tointeger(L, i); | 138 | lua_Integer n = lua_tointeger(L, i); |
137 | if (isnum != NULL) { | 139 | if (isnum != NULL) { |
138 | *isnum = (n != 0 || lua_isnumber(L, i)); | 140 | *isnum = (n != 0 || lua_isnumber(L, i)); |
139 | } | 141 | } |
140 | return n; | 142 | return n; |
141 | } | 143 | } |
142 | 144 | ||
@@ -183,14 +185,15 @@ COMPAT53_API int luaL_getsubtable (lua_State *L, int i, const char *name) { | |||
183 | } | 185 | } |
184 | 186 | ||
185 | 187 | ||
186 | COMPAT53_API int luaL_len (lua_State *L, int i) { | 188 | COMPAT53_API lua_Integer luaL_len (lua_State *L, int i) { |
187 | int res = 0, isnum = 0; | 189 | lua_Integer res = 0; |
190 | int isnum = 0; | ||
188 | luaL_checkstack(L, 1, "not enough stack slots"); | 191 | luaL_checkstack(L, 1, "not enough stack slots"); |
189 | lua_len(L, i); | 192 | lua_len(L, i); |
190 | res = (int)lua_tointegerx(L, -1, &isnum); | 193 | res = lua_tointegerx(L, -1, &isnum); |
191 | lua_pop(L, 1); | 194 | lua_pop(L, 1); |
192 | if (!isnum) | 195 | if (!isnum) |
193 | luaL_error(L, "object length is not a number"); | 196 | luaL_error(L, "object length is not an integer"); |
194 | return res; | 197 | return res; |
195 | } | 198 | } |
196 | 199 | ||
diff --git a/c-api/compat-5.3.h b/c-api/compat-5.3.h index 2309294..ba90d81 100644 --- a/c-api/compat-5.3.h +++ b/c-api/compat-5.3.h | |||
@@ -138,7 +138,7 @@ COMPAT53_API void luaL_checkstack (lua_State *L, int sp, const char *msg); | |||
138 | COMPAT53_API int luaL_getsubtable (lua_State* L, int i, const char *name); | 138 | COMPAT53_API int luaL_getsubtable (lua_State* L, int i, const char *name); |
139 | 139 | ||
140 | #define luaL_len COMPAT53_CONCAT(COMPAT53_PREFIX, L_len) | 140 | #define luaL_len COMPAT53_CONCAT(COMPAT53_PREFIX, L_len) |
141 | COMPAT53_API int luaL_len (lua_State *L, int i); | 141 | COMPAT53_API lua_Integer luaL_len (lua_State *L, int i); |
142 | 142 | ||
143 | #define luaL_setfuncs COMPAT53_CONCAT(COMPAT53_PREFIX, L_setfuncs) | 143 | #define luaL_setfuncs COMPAT53_CONCAT(COMPAT53_PREFIX, L_setfuncs) |
144 | COMPAT53_API void luaL_setfuncs (lua_State *L, const luaL_Reg *l, int nup); | 144 | COMPAT53_API void luaL_setfuncs (lua_State *L, const luaL_Reg *l, int nup); |