diff options
author | Philipp Janda <siffiejoe@gmx.net> | 2018-02-11 12:44:09 +0100 |
---|---|---|
committer | Philipp Janda <siffiejoe@gmx.net> | 2018-02-11 12:44:09 +0100 |
commit | d48f7f5e0932f573d18952642cfbd6da017f431c (patch) | |
tree | b343f3dc4787990bc4d669e9e4e465e14c639111 /c-api/compat-5.3.c | |
parent | 340f2f4777e8ad427a364c9c1ef562d40c60cb1d (diff) | |
download | lua-compat-5.3-d48f7f5e0932f573d18952642cfbd6da017f431c.tar.gz lua-compat-5.3-d48f7f5e0932f573d18952642cfbd6da017f431c.tar.bz2 lua-compat-5.3-d48f7f5e0932f573d18952642cfbd6da017f431c.zip |
Provide strict lua_tointegerx for Lua 5.2 as well.
Closes #40.
Diffstat (limited to 'c-api/compat-5.3.c')
-rw-r--r-- | c-api/compat-5.3.c | 32 |
1 files changed, 16 insertions, 16 deletions
diff --git a/c-api/compat-5.3.c b/c-api/compat-5.3.c index ebaf03f..370027a 100644 --- a/c-api/compat-5.3.c +++ b/c-api/compat-5.3.c | |||
@@ -204,22 +204,6 @@ COMPAT53_API void lua_rawsetp (lua_State *L, int i, const void *p) { | |||
204 | } | 204 | } |
205 | 205 | ||
206 | 206 | ||
207 | COMPAT53_API lua_Integer lua_tointegerx (lua_State *L, int i, int *isnum) { | ||
208 | int ok = 0; | ||
209 | lua_Number n = lua_tonumberx(L, i, &ok); | ||
210 | lua_Integer j = (lua_tointeger)(L, i); /* native lua_tointeger */ | ||
211 | if (isnum == NULL) | ||
212 | isnum = &ok; | ||
213 | if (ok && n == j) { | ||
214 | *isnum = 1; | ||
215 | return j; | ||
216 | } else { | ||
217 | *isnum = 0; | ||
218 | return 0; | ||
219 | } | ||
220 | } | ||
221 | |||
222 | |||
223 | COMPAT53_API lua_Number lua_tonumberx (lua_State *L, int i, int *isnum) { | 207 | COMPAT53_API lua_Number lua_tonumberx (lua_State *L, int i, int *isnum) { |
224 | lua_Number n = lua_tonumber(L, i); | 208 | lua_Number n = lua_tonumber(L, i); |
225 | if (isnum != NULL) { | 209 | if (isnum != NULL) { |
@@ -747,6 +731,22 @@ COMPAT53_API int lua_isinteger (lua_State *L, int index) { | |||
747 | } | 731 | } |
748 | 732 | ||
749 | 733 | ||
734 | COMPAT53_API lua_Integer lua_tointegerx (lua_State *L, int i, int *isnum) { | ||
735 | int ok = 0; | ||
736 | lua_Number n = lua_tonumberx(L, i, &ok); | ||
737 | if (ok) { | ||
738 | if (n == (lua_Integer)n) { | ||
739 | if (isnum) | ||
740 | *isnum = 1; | ||
741 | return (lua_Integer)n; | ||
742 | } | ||
743 | } | ||
744 | if (isnum) | ||
745 | *isnum = 0; | ||
746 | return 0; | ||
747 | } | ||
748 | |||
749 | |||
750 | static void compat53_reverse (lua_State *L, int a, int b) { | 750 | static void compat53_reverse (lua_State *L, int a, int b) { |
751 | for (; a < b; ++a, --b) { | 751 | for (; a < b; ++a, --b) { |
752 | lua_pushvalue(L, a); | 752 | lua_pushvalue(L, a); |