From 26679ea35bf261f2b5edc2fb2f5cc4df483fd50d Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Wed, 8 Nov 2017 12:50:23 -0200 Subject: new function 'luaV_flttointeger' to convert floats to integers (without string coercions) + string operands to bitwise operations handled by string metamethods --- lvm.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'lvm.h') diff --git a/lvm.h b/lvm.h index 6bb5818d..c2e25574 100644 --- a/lvm.h +++ b/lvm.h @@ -1,5 +1,5 @@ /* -** $Id: lvm.h,v 2.45 2017/06/29 15:06:44 roberto Exp roberto $ +** $Id: lvm.h,v 2.46 2017/07/07 16:34:32 roberto Exp roberto $ ** Lua virtual machine ** See Copyright Notice in lua.h */ @@ -53,6 +53,12 @@ (ttisinteger(o) ? (*(i) = ivalue(o), 1) : luaV_tointeger(o,i,LUA_FLOORN2I)) +/* convert an object to an integer (without string coercion) */ +#define tointegerns(o,i) \ + (ttisinteger(o) ? (*(i) = ivalue(o), 1) \ + : luaV_flttointeger(o,i,LUA_FLOORN2I)) + + #define intop(op,v1,v2) l_castU2S(l_castS2U(v1) op l_castS2U(v2)) #define luaV_rawequalobj(t1,t2) luaV_equalobj(NULL,t1,t2) @@ -100,6 +106,7 @@ LUAI_FUNC int luaV_lessthan (lua_State *L, const TValue *l, const TValue *r); LUAI_FUNC int luaV_lessequal (lua_State *L, const TValue *l, const TValue *r); LUAI_FUNC int luaV_tonumber_ (const TValue *obj, lua_Number *n); LUAI_FUNC int luaV_tointeger (const TValue *obj, lua_Integer *p, int mode); +LUAI_FUNC int luaV_flttointeger (const TValue *obj, lua_Integer *p, int mode); LUAI_FUNC void luaV_finishget (lua_State *L, const TValue *t, TValue *key, StkId val, const TValue *slot); LUAI_FUNC void luaV_finishset (lua_State *L, const TValue *t, TValue *key, -- cgit v1.2.3-55-g6feb