From d48f7f5e0932f573d18952642cfbd6da017f431c Mon Sep 17 00:00:00 2001 From: Philipp Janda Date: Sun, 11 Feb 2018 12:44:09 +0100 Subject: Provide strict lua_tointegerx for Lua 5.2 as well. Closes #40. --- c-api/compat-5.3.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) (limited to 'c-api/compat-5.3.c') 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) { } -COMPAT53_API lua_Integer lua_tointegerx (lua_State *L, int i, int *isnum) { - int ok = 0; - lua_Number n = lua_tonumberx(L, i, &ok); - lua_Integer j = (lua_tointeger)(L, i); /* native lua_tointeger */ - if (isnum == NULL) - isnum = &ok; - if (ok && n == j) { - *isnum = 1; - return j; - } else { - *isnum = 0; - return 0; - } -} - - COMPAT53_API lua_Number lua_tonumberx (lua_State *L, int i, int *isnum) { lua_Number n = lua_tonumber(L, i); if (isnum != NULL) { @@ -747,6 +731,22 @@ COMPAT53_API int lua_isinteger (lua_State *L, int index) { } +COMPAT53_API lua_Integer lua_tointegerx (lua_State *L, int i, int *isnum) { + int ok = 0; + lua_Number n = lua_tonumberx(L, i, &ok); + if (ok) { + if (n == (lua_Integer)n) { + if (isnum) + *isnum = 1; + return (lua_Integer)n; + } + } + if (isnum) + *isnum = 0; + return 0; +} + + static void compat53_reverse (lua_State *L, int a, int b) { for (; a < b; ++a, --b) { lua_pushvalue(L, a); -- cgit v1.2.3-55-g6feb