1997-09-16 12:25:59 -07:00
|
|
|
/*
|
2018-08-23 10:26:12 -07:00
|
|
|
** $Id: lvm.h $
|
1997-09-16 12:25:59 -07:00
|
|
|
** Lua virtual machine
|
|
|
|
** See Copyright Notice in lua.h
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef lvm_h
|
|
|
|
#define lvm_h
|
|
|
|
|
|
|
|
|
|
|
|
#include "ldo.h"
|
|
|
|
#include "lobject.h"
|
1998-07-12 09:16:43 -07:00
|
|
|
#include "ltm.h"
|
1997-09-16 12:25:59 -07:00
|
|
|
|
|
|
|
|
2014-07-30 07:42:44 -07:00
|
|
|
#if !defined(LUA_NOCVTN2S)
|
|
|
|
#define cvt2str(o) ttisnumber(o)
|
|
|
|
#else
|
2014-08-01 10:24:02 -07:00
|
|
|
#define cvt2str(o) 0 /* no conversion from numbers to strings */
|
2014-07-30 07:42:44 -07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
#if !defined(LUA_NOCVTS2N)
|
|
|
|
#define cvt2num(o) ttisstring(o)
|
|
|
|
#else
|
2014-08-01 10:24:02 -07:00
|
|
|
#define cvt2num(o) 0 /* no conversion from strings to numbers */
|
2014-07-30 07:42:44 -07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2015-02-20 06:27:53 -08:00
|
|
|
/*
|
|
|
|
** You can define LUA_FLOORN2I if you want to convert floats to integers
|
|
|
|
** by flooring them (instead of raising an error if they are not
|
|
|
|
** integral values)
|
|
|
|
*/
|
|
|
|
#if !defined(LUA_FLOORN2I)
|
2019-12-05 09:14:29 -08:00
|
|
|
#define LUA_FLOORN2I F2Ieq
|
2015-02-20 06:27:53 -08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2019-12-05 09:14:29 -08:00
|
|
|
/*
|
|
|
|
** Rounding modes for float->integer coercion
|
|
|
|
*/
|
|
|
|
typedef enum {
|
2020-04-23 10:48:15 -07:00
|
|
|
F2Ieq, /* no rounding; accepts only integral values */
|
2019-12-05 09:14:29 -08:00
|
|
|
F2Ifloor, /* takes the floor of the number */
|
2020-04-23 10:48:15 -07:00
|
|
|
F2Iceil /* takes the ceil of the number */
|
2019-12-05 09:14:29 -08:00
|
|
|
} F2Imod;
|
|
|
|
|
|
|
|
|
2017-07-07 09:34:32 -07:00
|
|
|
/* convert an object to a float (including string coercion) */
|
2013-04-26 09:03:50 -07:00
|
|
|
#define tonumber(o,n) \
|
|
|
|
(ttisfloat(o) ? (*(n) = fltvalue(o), 1) : luaV_tonumber_(o,n))
|
1997-09-16 12:25:59 -07:00
|
|
|
|
2017-07-07 09:34:32 -07:00
|
|
|
|
|
|
|
/* convert an object to a float (without string coercion) */
|
|
|
|
#define tonumberns(o,n) \
|
|
|
|
(ttisfloat(o) ? ((n) = fltvalue(o), 1) : \
|
|
|
|
(ttisinteger(o) ? ((n) = cast_num(ivalue(o)), 1) : 0))
|
|
|
|
|
|
|
|
|
|
|
|
/* convert an object to an integer (including string coercion) */
|
2013-04-29 10:12:50 -07:00
|
|
|
#define tointeger(o,i) \
|
2021-02-24 06:14:44 -08:00
|
|
|
(l_likely(ttisinteger(o)) ? (*(i) = ivalue(o), 1) \
|
|
|
|
: luaV_tointeger(o,i,LUA_FLOORN2I))
|
2013-04-29 10:12:50 -07:00
|
|
|
|
2017-07-07 09:34:32 -07:00
|
|
|
|
2017-11-08 06:50:23 -08:00
|
|
|
/* convert an object to an integer (without string coercion) */
|
|
|
|
#define tointegerns(o,i) \
|
2021-02-24 06:14:44 -08:00
|
|
|
(l_likely(ttisinteger(o)) ? (*(i) = ivalue(o), 1) \
|
|
|
|
: luaV_tointegerns(o,i,LUA_FLOORN2I))
|
2017-11-08 06:50:23 -08:00
|
|
|
|
|
|
|
|
2014-04-15 09:32:49 -07:00
|
|
|
#define intop(op,v1,v2) l_castU2S(l_castS2U(v1) op l_castS2U(v2))
|
2002-06-13 06:39:55 -07:00
|
|
|
|
2013-04-15 08:44:46 -07:00
|
|
|
#define luaV_rawequalobj(t1,t2) luaV_equalobj(NULL,t1,t2)
|
2007-02-09 05:04:52 -08:00
|
|
|
|
2011-05-31 11:24:36 -07:00
|
|
|
|
2015-07-20 11:24:50 -07:00
|
|
|
/*
|
2018-02-23 05:16:18 -08:00
|
|
|
** fast track for 'gettable': if 't' is a table and 't[k]' is present,
|
2017-05-11 11:57:46 -07:00
|
|
|
** return 1 with 'slot' pointing to 't[k]' (position of final result).
|
|
|
|
** Otherwise, return 0 (meaning it will have to check metamethod)
|
2018-02-23 05:16:18 -08:00
|
|
|
** with 'slot' pointing to an empty 't[k]' (if 't' is a table) or NULL
|
2017-05-11 11:57:46 -07:00
|
|
|
** (otherwise). 'f' is the raw get function to use.
|
2015-07-20 11:24:50 -07:00
|
|
|
*/
|
2016-01-05 08:07:21 -08:00
|
|
|
#define luaV_fastget(L,t,k,slot,f) \
|
2015-07-20 11:24:50 -07:00
|
|
|
(!ttistable(t) \
|
2016-01-05 08:07:21 -08:00
|
|
|
? (slot = NULL, 0) /* not a table; 'slot' is NULL and result is 0 */ \
|
|
|
|
: (slot = f(hvalue(t), k), /* else, do raw access */ \
|
2018-02-23 05:16:18 -08:00
|
|
|
!isempty(slot))) /* result not empty? */
|
2015-07-20 11:24:50 -07:00
|
|
|
|
2017-05-11 11:57:46 -07:00
|
|
|
|
2015-07-20 11:24:50 -07:00
|
|
|
/*
|
2017-05-11 11:57:46 -07:00
|
|
|
** Special case of 'luaV_fastget' for integers, inlining the fast case
|
|
|
|
** of 'luaH_getint'.
|
2015-07-20 11:24:50 -07:00
|
|
|
*/
|
2017-05-11 11:57:46 -07:00
|
|
|
#define luaV_fastgeti(L,t,k,slot) \
|
|
|
|
(!ttistable(t) \
|
|
|
|
? (slot = NULL, 0) /* not a table; 'slot' is NULL and result is 0 */ \
|
2018-06-15 07:14:20 -07:00
|
|
|
: (slot = (l_castS2U(k) - 1u < hvalue(t)->alimit) \
|
2017-05-11 11:57:46 -07:00
|
|
|
? &hvalue(t)->array[k - 1] : luaH_getint(hvalue(t), k), \
|
2018-02-23 05:16:18 -08:00
|
|
|
!isempty(slot))) /* result not empty? */
|
2015-07-20 11:24:50 -07:00
|
|
|
|
|
|
|
|
2015-09-09 06:44:07 -07:00
|
|
|
/*
|
2017-05-11 11:57:46 -07:00
|
|
|
** Finish a fast set operation (when fast get succeeds). In that case,
|
2017-06-09 12:16:41 -07:00
|
|
|
** 'slot' points to the place to put the value.
|
2015-09-09 06:44:07 -07:00
|
|
|
*/
|
2017-05-11 11:57:46 -07:00
|
|
|
#define luaV_finishfastset(L,t,slot,v) \
|
2017-06-01 13:23:27 -07:00
|
|
|
{ setobj2t(L, cast(TValue *,slot), v); \
|
2018-02-19 12:06:56 -08:00
|
|
|
luaC_barrierback(L, gcvalue(t), v); }
|
2017-05-11 11:57:46 -07:00
|
|
|
|
2016-12-22 05:08:50 -08:00
|
|
|
|
2015-08-03 12:50:49 -07:00
|
|
|
|
|
|
|
|
2013-04-15 08:44:46 -07:00
|
|
|
LUAI_FUNC int luaV_equalobj (lua_State *L, const TValue *t1, const TValue *t2);
|
2005-04-25 12:24:10 -07:00
|
|
|
LUAI_FUNC int luaV_lessthan (lua_State *L, const TValue *l, const TValue *r);
|
2009-06-17 09:17:14 -07:00
|
|
|
LUAI_FUNC int luaV_lessequal (lua_State *L, const TValue *l, const TValue *r);
|
2013-04-26 09:03:50 -07:00
|
|
|
LUAI_FUNC int luaV_tonumber_ (const TValue *obj, lua_Number *n);
|
2019-12-05 09:14:29 -08:00
|
|
|
LUAI_FUNC int luaV_tointeger (const TValue *obj, lua_Integer *p, F2Imod mode);
|
|
|
|
LUAI_FUNC int luaV_tointegerns (const TValue *obj, lua_Integer *p,
|
|
|
|
F2Imod mode);
|
|
|
|
LUAI_FUNC int luaV_flttointeger (lua_Number n, lua_Integer *p, F2Imod mode);
|
2015-07-20 11:24:50 -07:00
|
|
|
LUAI_FUNC void luaV_finishget (lua_State *L, const TValue *t, TValue *key,
|
2016-01-05 08:07:21 -08:00
|
|
|
StkId val, const TValue *slot);
|
2015-08-03 12:50:49 -07:00
|
|
|
LUAI_FUNC void luaV_finishset (lua_State *L, const TValue *t, TValue *key,
|
2017-06-29 08:06:44 -07:00
|
|
|
TValue *val, const TValue *slot);
|
2009-03-10 10:14:37 -07:00
|
|
|
LUAI_FUNC void luaV_finishOp (lua_State *L);
|
2017-11-29 05:02:17 -08:00
|
|
|
LUAI_FUNC void luaV_execute (lua_State *L, CallInfo *ci);
|
2009-05-27 10:11:27 -07:00
|
|
|
LUAI_FUNC void luaV_concat (lua_State *L, int total);
|
2018-11-05 10:10:42 -08:00
|
|
|
LUAI_FUNC lua_Integer luaV_idiv (lua_State *L, lua_Integer x, lua_Integer y);
|
2013-04-25 12:12:41 -07:00
|
|
|
LUAI_FUNC lua_Integer luaV_mod (lua_State *L, lua_Integer x, lua_Integer y);
|
2018-08-28 08:36:58 -07:00
|
|
|
LUAI_FUNC lua_Number luaV_modf (lua_State *L, lua_Number x, lua_Number y);
|
2013-12-30 12:47:58 -08:00
|
|
|
LUAI_FUNC lua_Integer luaV_shiftl (lua_Integer x, lua_Integer y);
|
2009-12-17 08:20:01 -08:00
|
|
|
LUAI_FUNC void luaV_objlen (lua_State *L, StkId ra, const TValue *rb);
|
1997-09-16 12:25:59 -07:00
|
|
|
|
|
|
|
#endif
|