aboutsummaryrefslogtreecommitdiff
path: root/lvm.h
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2019-12-05 14:14:29 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2019-12-05 14:14:29 -0300
commitd30569c06407529cc6e99f4a35ae5f9bfe6fa940 (patch)
tree51e560713cb01203d94d792a1e80f38ba7f84c52 /lvm.h
parent2d92102dee88a81711dca8e8ea3ef0ea9d732283 (diff)
downloadlua-d30569c06407529cc6e99f4a35ae5f9bfe6fa940.tar.gz
lua-d30569c06407529cc6e99f4a35ae5f9bfe6fa940.tar.bz2
lua-d30569c06407529cc6e99f4a35ae5f9bfe6fa940.zip
Using an enumeration for float->integer coercion modes
Diffstat (limited to 'lvm.h')
-rw-r--r--lvm.h19
1 files changed, 15 insertions, 4 deletions
diff --git a/lvm.h b/lvm.h
index 7e8ec715..71038572 100644
--- a/lvm.h
+++ b/lvm.h
@@ -33,10 +33,20 @@
33** integral values) 33** integral values)
34*/ 34*/
35#if !defined(LUA_FLOORN2I) 35#if !defined(LUA_FLOORN2I)
36#define LUA_FLOORN2I 0 36#define LUA_FLOORN2I F2Ieq
37#endif 37#endif
38 38
39 39
40/*
41** Rounding modes for float->integer coercion
42 */
43typedef enum {
44 F2Ieq, /* no rounding; accepts only integral values */
45 F2Ifloor, /* takes the floor of the number */
46 F2Iceil, /* takes the ceil of the number */
47} F2Imod;
48
49
40/* convert an object to a float (including string coercion) */ 50/* convert an object to a float (including string coercion) */
41#define tonumber(o,n) \ 51#define tonumber(o,n) \
42 (ttisfloat(o) ? (*(n) = fltvalue(o), 1) : luaV_tonumber_(o,n)) 52 (ttisfloat(o) ? (*(n) = fltvalue(o), 1) : luaV_tonumber_(o,n))
@@ -104,9 +114,10 @@ LUAI_FUNC int luaV_equalobj (lua_State *L, const TValue *t1, const TValue *t2);
104LUAI_FUNC int luaV_lessthan (lua_State *L, const TValue *l, const TValue *r); 114LUAI_FUNC int luaV_lessthan (lua_State *L, const TValue *l, const TValue *r);
105LUAI_FUNC int luaV_lessequal (lua_State *L, const TValue *l, const TValue *r); 115LUAI_FUNC int luaV_lessequal (lua_State *L, const TValue *l, const TValue *r);
106LUAI_FUNC int luaV_tonumber_ (const TValue *obj, lua_Number *n); 116LUAI_FUNC int luaV_tonumber_ (const TValue *obj, lua_Number *n);
107LUAI_FUNC int luaV_tointeger (const TValue *obj, lua_Integer *p, int mode); 117LUAI_FUNC int luaV_tointeger (const TValue *obj, lua_Integer *p, F2Imod mode);
108LUAI_FUNC int luaV_tointegerns (const TValue *obj, lua_Integer *p, int mode); 118LUAI_FUNC int luaV_tointegerns (const TValue *obj, lua_Integer *p,
109LUAI_FUNC int luaV_flttointeger (lua_Number n, lua_Integer *p, int mode); 119 F2Imod mode);
120LUAI_FUNC int luaV_flttointeger (lua_Number n, lua_Integer *p, F2Imod mode);
110LUAI_FUNC void luaV_finishget (lua_State *L, const TValue *t, TValue *key, 121LUAI_FUNC void luaV_finishget (lua_State *L, const TValue *t, TValue *key,
111 StkId val, const TValue *slot); 122 StkId val, const TValue *slot);
112LUAI_FUNC void luaV_finishset (lua_State *L, const TValue *t, TValue *key, 123LUAI_FUNC void luaV_finishset (lua_State *L, const TValue *t, TValue *key,