1997-11-19 20:31:19 +03:00
|
|
|
/*
|
2018-07-11 22:11:50 +03:00
|
|
|
** $Id: lstate.h $
|
1997-11-19 20:31:19 +03:00
|
|
|
** Global State
|
|
|
|
** See Copyright Notice in lua.h
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef lstate_h
|
|
|
|
#define lstate_h
|
|
|
|
|
1998-06-03 00:37:04 +04:00
|
|
|
#include "lua.h"
|
2001-12-05 23:15:18 +03:00
|
|
|
|
|
|
|
#include "lobject.h"
|
|
|
|
#include "ltm.h"
|
2002-10-08 22:46:08 +04:00
|
|
|
#include "lzio.h"
|
1997-11-19 20:31:19 +03:00
|
|
|
|
|
|
|
|
2008-06-26 23:42:45 +04:00
|
|
|
/*
|
2013-09-11 18:09:55 +04:00
|
|
|
** Some notes about garbage-collected objects: All objects in Lua must
|
|
|
|
** be kept somehow accessible until being freed, so all objects always
|
|
|
|
** belong to one (and only one) of these lists, using field 'next' of
|
|
|
|
** the 'CommonHeader' for the link:
|
2008-06-26 23:42:45 +04:00
|
|
|
**
|
2014-10-30 21:53:28 +03:00
|
|
|
** 'allgc': all objects not marked for finalization;
|
|
|
|
** 'finobj': all objects marked for finalization;
|
2016-12-22 16:08:50 +03:00
|
|
|
** 'tobefnz': all objects ready to be finalized;
|
2014-10-30 21:53:28 +03:00
|
|
|
** 'fixedgc': all objects that are not to be collected (currently
|
2013-08-22 00:09:51 +04:00
|
|
|
** only small strings, such as reserved words).
|
2017-02-15 21:52:13 +03:00
|
|
|
**
|
2019-05-28 21:46:49 +03:00
|
|
|
** For the generational collector, some of these lists have marks for
|
|
|
|
** generations. Each mark points to the first element in the list for
|
|
|
|
** that particular generation; that generation goes until the next mark.
|
|
|
|
**
|
|
|
|
** 'allgc' -> 'survival': new objects;
|
|
|
|
** 'survival' -> 'old': objects that survived one collection;
|
|
|
|
** 'old' -> 'reallyold': objects that became old in last collection;
|
|
|
|
** 'reallyold' -> NULL: objects old for more than one cycle.
|
|
|
|
**
|
|
|
|
** 'finobj' -> 'finobjsur': new objects marked for finalization;
|
|
|
|
** 'finobjsur' -> 'finobjold': survived """";
|
|
|
|
** 'finobjold' -> 'finobjrold': just old """";
|
|
|
|
** 'finobjrold' -> NULL: really old """".
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2017-02-15 21:52:13 +03:00
|
|
|
** Moreover, there is another set of lists that control gray objects.
|
|
|
|
** These lists are linked by fields 'gclist'. (All objects that
|
|
|
|
** can become gray have such a field. The field is not the same
|
|
|
|
** in all objects, but it always has this name.) Any gray object
|
|
|
|
** must belong to one of these lists, and all objects in these lists
|
|
|
|
** must be gray:
|
|
|
|
**
|
|
|
|
** 'gray': regular gray objects, still waiting to be visited.
|
|
|
|
** 'grayagain': objects that must be revisited at the atomic phase.
|
|
|
|
** That includes
|
|
|
|
** - black objects got in a write barrier;
|
|
|
|
** - all kinds of weak tables during propagation phase;
|
|
|
|
** - all threads.
|
|
|
|
** 'weak': tables with weak values to be cleared;
|
|
|
|
** 'ephemeron': ephemeron tables with white->white entries;
|
|
|
|
** 'allweak': tables with weak keys and/or weak values to be cleared.
|
2008-06-26 23:42:45 +04:00
|
|
|
*/
|
|
|
|
|
1999-05-10 17:54:01 +04:00
|
|
|
|
2018-07-11 22:11:50 +03:00
|
|
|
|
2018-12-27 19:32:29 +03:00
|
|
|
/*
|
2018-07-11 22:11:50 +03:00
|
|
|
** About 'nCcalls': each thread in Lua (a lua_State) keeps a count of
|
2019-06-12 16:31:38 +03:00
|
|
|
** how many "C calls" it still can do in the C stack, to avoid C-stack
|
|
|
|
** overflow. This count is very rough approximation; it considers only
|
|
|
|
** recursive functions inside the interpreter, as non-recursive calls
|
|
|
|
** can be considered using a fixed (although unknown) amount of stack
|
|
|
|
** space.
|
2018-07-11 22:11:50 +03:00
|
|
|
**
|
2019-06-12 16:31:38 +03:00
|
|
|
** The count has two parts: the lower part is the count itself; the
|
|
|
|
** higher part counts the number of non-yieldable calls in the stack.
|
|
|
|
** (They are together so that we can change both with one instruction.)
|
2018-12-27 19:32:29 +03:00
|
|
|
**
|
2019-07-05 21:03:15 +03:00
|
|
|
** Because calls to external C functions can use an unknown amount
|
2018-12-27 19:32:29 +03:00
|
|
|
** of space (e.g., functions using an auxiliary buffer), calls
|
2019-06-12 16:31:38 +03:00
|
|
|
** to these functions add more than one to the count (see CSTACKCF).
|
2018-12-27 19:32:29 +03:00
|
|
|
**
|
2019-06-12 16:31:38 +03:00
|
|
|
** The proper count excludes the number of CallInfo structures allocated
|
|
|
|
** by Lua, as a kind of "potential" calls. So, when Lua calls a function
|
|
|
|
** (and "consumes" one CallInfo), it needs neither to decrement nor to
|
|
|
|
** check 'nCcalls', as its use of C stack is already accounted for.
|
2018-07-11 22:11:50 +03:00
|
|
|
*/
|
|
|
|
|
2018-12-27 19:32:29 +03:00
|
|
|
/* number of "C stack slots" used by an external C function */
|
|
|
|
#define CSTACKCF 10
|
|
|
|
|
2019-06-12 16:31:38 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
** The C-stack size is sliced in the following zones:
|
|
|
|
** - larger than CSTACKERR: normal stack;
|
|
|
|
** - [CSTACKMARK, CSTACKERR]: buffer zone to signal a stack overflow;
|
|
|
|
** - [CSTACKCF, CSTACKERRMARK]: error-handling zone;
|
|
|
|
** - below CSTACKERRMARK: buffer zone to signal overflow during overflow;
|
|
|
|
** (Because the counter can be decremented CSTACKCF at once, we need
|
|
|
|
** the so called "buffer zones", with at least that size, to properly
|
|
|
|
** detect a change from one zone to the next.)
|
|
|
|
*/
|
|
|
|
#define CSTACKERR (8 * CSTACKCF)
|
|
|
|
#define CSTACKMARK (CSTACKERR - (CSTACKCF + 2))
|
|
|
|
#define CSTACKERRMARK (CSTACKCF + 2)
|
|
|
|
|
|
|
|
|
2019-06-18 22:52:22 +03:00
|
|
|
/* initial limit for the C-stack of threads */
|
|
|
|
#define CSTACKTHREAD (2 * CSTACKERR)
|
|
|
|
|
|
|
|
|
2018-12-27 19:32:29 +03:00
|
|
|
/* true if this thread does not have non-yieldable calls in the stack */
|
|
|
|
#define yieldable(L) (((L)->nCcalls & 0xffff0000) == 0)
|
|
|
|
|
|
|
|
/* real number of C calls */
|
|
|
|
#define getCcalls(L) ((L)->nCcalls & 0xffff)
|
|
|
|
|
|
|
|
|
|
|
|
/* Increment the number of non-yieldable calls */
|
|
|
|
#define incnny(L) ((L)->nCcalls += 0x10000)
|
|
|
|
|
|
|
|
/* Decrement the number of non-yieldable calls */
|
|
|
|
#define decnny(L) ((L)->nCcalls -= 0x10000)
|
|
|
|
|
2019-06-12 16:31:38 +03:00
|
|
|
/* Increment the number of non-yieldable calls and decrement nCcalls */
|
|
|
|
#define incXCcalls(L) ((L)->nCcalls += 0x10000 - CSTACKCF)
|
2018-12-27 19:32:29 +03:00
|
|
|
|
2019-06-12 16:31:38 +03:00
|
|
|
/* Decrement the number of non-yieldable calls and increment nCcalls */
|
|
|
|
#define decXCcalls(L) ((L)->nCcalls -= 0x10000 - CSTACKCF)
|
2018-12-27 19:32:29 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2000-09-25 20:22:42 +04:00
|
|
|
struct lua_longjmp; /* defined in ldo.c */
|
2001-12-05 23:15:18 +03:00
|
|
|
|
|
|
|
|
2015-12-14 14:54:49 +03:00
|
|
|
/*
|
2016-12-22 16:08:50 +03:00
|
|
|
** Atomic type (relative to signals) to better ensure that 'lua_sethook'
|
2015-12-14 14:54:49 +03:00
|
|
|
** is thread safe
|
|
|
|
*/
|
|
|
|
#if !defined(l_signalT)
|
|
|
|
#include <signal.h>
|
|
|
|
#define l_signalT sig_atomic_t
|
|
|
|
#endif
|
|
|
|
|
2002-01-26 01:14:54 +03:00
|
|
|
|
2002-08-05 21:36:24 +04:00
|
|
|
/* extra stack space to handle TM calls and some other extras */
|
2002-05-08 21:34:23 +04:00
|
|
|
#define EXTRA_STACK 5
|
2002-01-26 01:14:54 +03:00
|
|
|
|
|
|
|
|
|
|
|
#define BASIC_STACK_SIZE (2*LUA_MINSTACK)
|
|
|
|
|
1997-11-19 20:31:19 +03:00
|
|
|
|
2008-02-11 18:45:30 +03:00
|
|
|
/* kinds of Garbage Collection */
|
2017-04-24 19:59:26 +03:00
|
|
|
#define KGC_INC 0 /* incremental gc */
|
2017-02-24 00:07:34 +03:00
|
|
|
#define KGC_GEN 1 /* generational gc */
|
2008-02-11 18:45:30 +03:00
|
|
|
|
1997-11-19 20:31:19 +03:00
|
|
|
|
1999-05-10 17:54:01 +04:00
|
|
|
typedef struct stringtable {
|
2013-08-21 23:21:16 +04:00
|
|
|
TString **hash;
|
2013-08-22 19:21:48 +04:00
|
|
|
int nuse; /* number of elements */
|
|
|
|
int size;
|
1997-11-19 20:31:19 +03:00
|
|
|
} stringtable;
|
|
|
|
|
|
|
|
|
2017-11-07 16:25:26 +03:00
|
|
|
/*
|
|
|
|
** Information about a call.
|
|
|
|
*/
|
|
|
|
typedef struct CallInfo {
|
|
|
|
StkId func; /* function index in the stack */
|
|
|
|
StkId top; /* top for this function */
|
|
|
|
struct CallInfo *previous, *next; /* dynamic call link */
|
|
|
|
union {
|
|
|
|
struct { /* only for Lua functions */
|
|
|
|
const Instruction *savedpc;
|
2020-05-22 17:40:34 +03:00
|
|
|
volatile l_signalT trap;
|
2018-02-09 18:16:06 +03:00
|
|
|
int nextraargs; /* # of extra arguments in vararg functions */
|
2017-11-07 16:25:26 +03:00
|
|
|
} l;
|
|
|
|
struct { /* only for C functions */
|
|
|
|
lua_KFunction k; /* continuation in case of yields */
|
|
|
|
ptrdiff_t old_errfunc;
|
|
|
|
lua_KContext ctx; /* context info. in case of yields */
|
|
|
|
} c;
|
|
|
|
} u;
|
|
|
|
union {
|
|
|
|
int funcidx; /* called-function index */
|
|
|
|
int nyield; /* number of values yielded */
|
2019-07-05 21:03:15 +03:00
|
|
|
struct { /* info about transferred values (for call/return hooks) */
|
|
|
|
unsigned short ftransfer; /* offset of first value transferred */
|
|
|
|
unsigned short ntransfer; /* number of values transferred */
|
2018-02-17 22:29:29 +03:00
|
|
|
} transferinfo;
|
2017-11-07 16:25:26 +03:00
|
|
|
} u2;
|
|
|
|
short nresults; /* expected number of results from this function */
|
2018-02-17 22:29:29 +03:00
|
|
|
unsigned short callstatus;
|
2017-11-07 16:25:26 +03:00
|
|
|
} CallInfo;
|
|
|
|
|
2002-07-16 18:26:56 +04:00
|
|
|
|
2008-08-26 17:27:42 +04:00
|
|
|
/*
|
|
|
|
** Bits in CallInfo status
|
|
|
|
*/
|
2014-06-12 23:07:30 +04:00
|
|
|
#define CIST_OAH (1<<0) /* original value of 'allowhook' */
|
2017-12-19 19:40:17 +03:00
|
|
|
#define CIST_C (1<<1) /* call is running a C function */
|
2017-11-07 16:25:26 +03:00
|
|
|
#define CIST_HOOKED (1<<2) /* call is running a debug hook */
|
2017-11-23 19:41:16 +03:00
|
|
|
#define CIST_YPCALL (1<<3) /* call is a yieldable protected call */
|
|
|
|
#define CIST_TAIL (1<<4) /* call was tail called */
|
|
|
|
#define CIST_HOOKYIELD (1<<5) /* last hook called yielded */
|
2018-08-24 16:17:54 +03:00
|
|
|
#define CIST_FIN (1<<6) /* call is running a finalizer */
|
|
|
|
#define CIST_TRAN (1<<7) /* 'ci' has transfer information */
|
|
|
|
#if defined(LUA_COMPAT_LT_LE)
|
|
|
|
#define CIST_LEQ (1<<8) /* using __lt for __le */
|
|
|
|
#endif
|
2002-07-16 18:26:56 +04:00
|
|
|
|
2017-12-19 19:40:17 +03:00
|
|
|
/* active function is a Lua function */
|
|
|
|
#define isLua(ci) (!((ci)->callstatus & CIST_C))
|
|
|
|
|
|
|
|
/* call is running Lua code (not a hook) */
|
|
|
|
#define isLuacode(ci) (!((ci)->callstatus & (CIST_C | CIST_HOOKED)))
|
2001-12-18 23:52:30 +03:00
|
|
|
|
2014-06-12 23:07:30 +04:00
|
|
|
/* assume that CIST_OAH has offset 0 and that 'v' is strictly 0/1 */
|
|
|
|
#define setoah(st,v) ((st) = ((st) & ~CIST_OAH) | (v))
|
|
|
|
#define getoah(st) ((st) & CIST_OAH)
|
|
|
|
|
2001-12-18 23:52:30 +03:00
|
|
|
|
2001-01-19 16:20:30 +03:00
|
|
|
/*
|
2014-10-25 15:50:46 +04:00
|
|
|
** 'global state', shared by all threads of this state
|
2001-01-19 16:20:30 +03:00
|
|
|
*/
|
|
|
|
typedef struct global_State {
|
2005-02-23 20:30:22 +03:00
|
|
|
lua_Alloc frealloc; /* function to reallocate memory */
|
2014-10-25 15:50:46 +04:00
|
|
|
void *ud; /* auxiliary data to 'frealloc' */
|
2015-07-04 19:33:17 +03:00
|
|
|
l_mem totalbytes; /* number of bytes currently allocated - GCdebt */
|
2010-12-20 22:40:07 +03:00
|
|
|
l_mem GCdebt; /* bytes allocated not yet compensated by the collector */
|
2012-05-22 21:50:39 +04:00
|
|
|
lu_mem GCestimate; /* an estimate of the non-garbage memory in use */
|
2019-01-30 16:44:42 +03:00
|
|
|
lu_mem lastatomic; /* see function 'genstep' in file 'lgc.c' */
|
2010-03-25 22:37:23 +03:00
|
|
|
stringtable strt; /* hash table for strings */
|
|
|
|
TValue l_registry;
|
2018-06-15 22:31:22 +03:00
|
|
|
TValue nilvalue; /* a nil value */
|
2012-02-02 01:57:15 +04:00
|
|
|
unsigned int seed; /* randomized seed for hashes */
|
2004-08-25 00:12:06 +04:00
|
|
|
lu_byte currentwhite;
|
|
|
|
lu_byte gcstate; /* state of garbage collector */
|
2008-02-11 18:45:30 +03:00
|
|
|
lu_byte gckind; /* kind of GC running */
|
2017-04-19 20:02:50 +03:00
|
|
|
lu_byte genminormul; /* control for minor generational collections */
|
|
|
|
lu_byte genmajormul; /* control for major generational collections */
|
2010-12-20 21:17:46 +03:00
|
|
|
lu_byte gcrunning; /* true if GC is running */
|
2017-04-24 19:59:26 +03:00
|
|
|
lu_byte gcemergency; /* true if this is an emergency collection */
|
2017-05-26 22:14:29 +03:00
|
|
|
lu_byte gcpause; /* size of pause between successive GCs */
|
|
|
|
lu_byte gcstepmul; /* GC "speed" */
|
|
|
|
lu_byte gcstepsize; /* (log2 of) GC granularity */
|
2010-03-24 16:07:01 +03:00
|
|
|
GCObject *allgc; /* list of all collectable objects */
|
2013-08-30 23:14:26 +04:00
|
|
|
GCObject **sweepgc; /* current position of sweep in list */
|
2013-09-03 19:37:10 +04:00
|
|
|
GCObject *finobj; /* list of collectable objects with finalizers */
|
2003-11-18 17:55:11 +03:00
|
|
|
GCObject *gray; /* list of gray objects */
|
2003-12-04 21:52:23 +03:00
|
|
|
GCObject *grayagain; /* list of objects to be traversed atomically */
|
2008-02-19 21:55:09 +03:00
|
|
|
GCObject *weak; /* list of tables with weak values */
|
|
|
|
GCObject *ephemeron; /* list of ephemeron tables (weak keys) */
|
2007-10-31 18:41:19 +03:00
|
|
|
GCObject *allweak; /* list of all-weak tables */
|
2008-06-26 23:42:45 +04:00
|
|
|
GCObject *tobefnz; /* list of userdata to be GC */
|
2013-08-22 00:09:51 +04:00
|
|
|
GCObject *fixedgc; /* list of objects not to be collected */
|
2017-02-24 00:07:34 +03:00
|
|
|
/* fields for generational collector */
|
|
|
|
GCObject *survival; /* start of objects that survived one GC cycle */
|
2017-04-05 19:50:51 +03:00
|
|
|
GCObject *old; /* start of old objects */
|
|
|
|
GCObject *reallyold; /* old objects with more than one cycle */
|
|
|
|
GCObject *finobjsur; /* list of survival objects with finalizers */
|
|
|
|
GCObject *finobjold; /* list of old objects with finalizers */
|
|
|
|
GCObject *finobjrold; /* list of really old objects with finalizers */
|
2014-02-18 17:39:37 +04:00
|
|
|
struct lua_State *twups; /* list of threads with open upvalues */
|
2002-04-16 21:08:28 +04:00
|
|
|
lua_CFunction panic; /* to be called in unprotected errors */
|
2002-10-26 00:05:28 +04:00
|
|
|
struct lua_State *mainthread;
|
2018-02-15 21:06:24 +03:00
|
|
|
TString *memerrmsg; /* message for memory-allocation errors */
|
2010-03-22 21:28:03 +03:00
|
|
|
TString *tmname[TM_N]; /* array with tag-method names */
|
2010-04-12 20:07:29 +04:00
|
|
|
struct Table *mt[LUA_NUMTAGS]; /* metatables for basic types */
|
2015-09-22 17:18:24 +03:00
|
|
|
TString *strcache[STRCACHE_N][STRCACHE_M]; /* cache for strings in API */
|
2018-12-28 20:42:34 +03:00
|
|
|
lua_WarnFunction warnf; /* warning function */
|
|
|
|
void *ud_warn; /* auxiliary data to 'warnf' */
|
2019-06-18 22:52:22 +03:00
|
|
|
unsigned int Cstacklimit; /* current limit for the C stack */
|
2001-01-19 16:20:30 +03:00
|
|
|
} global_State;
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2014-10-25 15:50:46 +04:00
|
|
|
** 'per thread' state
|
2001-01-19 16:20:30 +03:00
|
|
|
*/
|
|
|
|
struct lua_State {
|
2002-10-26 00:05:28 +04:00
|
|
|
CommonHeader;
|
2006-02-06 21:27:59 +03:00
|
|
|
lu_byte status;
|
2018-12-27 19:32:29 +03:00
|
|
|
lu_byte allowhook;
|
|
|
|
unsigned short nci; /* number of items in 'ci' list */
|
2001-01-19 16:20:30 +03:00
|
|
|
StkId top; /* first free slot in the stack */
|
2005-07-09 17:22:34 +04:00
|
|
|
global_State *l_G;
|
2017-11-07 16:25:26 +03:00
|
|
|
CallInfo *ci; /* call info for current function */
|
2001-01-19 16:20:30 +03:00
|
|
|
StkId stack_last; /* last free slot in the stack */
|
2001-03-07 21:09:25 +03:00
|
|
|
StkId stack; /* stack base */
|
2013-08-27 22:53:35 +04:00
|
|
|
UpVal *openupval; /* list of open upvalues in this stack */
|
2002-11-13 14:32:26 +03:00
|
|
|
GCObject *gclist;
|
2014-02-18 17:39:37 +04:00
|
|
|
struct lua_State *twups; /* list of threads with open upvalues */
|
2002-08-05 21:36:24 +04:00
|
|
|
struct lua_longjmp *errorJmp; /* current error recover point */
|
2017-11-07 16:25:26 +03:00
|
|
|
CallInfo base_ci; /* CallInfo for first level (C calling Lua) */
|
2015-12-16 19:39:38 +03:00
|
|
|
volatile lua_Hook hook;
|
2014-07-23 21:15:43 +04:00
|
|
|
ptrdiff_t errfunc; /* current error handling function (stack index) */
|
2018-12-27 19:32:29 +03:00
|
|
|
l_uint32 nCcalls; /* number of allowed nested C calls - 'nci' */
|
2020-07-17 17:01:05 +03:00
|
|
|
int oldpc; /* last pc traced */
|
2014-07-23 21:15:43 +04:00
|
|
|
int stacksize;
|
|
|
|
int basehookcount;
|
|
|
|
int hookcount;
|
2020-05-22 17:40:34 +03:00
|
|
|
volatile l_signalT hookmask;
|
1998-06-03 00:37:04 +04:00
|
|
|
};
|
1997-11-19 20:31:19 +03:00
|
|
|
|
|
|
|
|
2005-07-09 17:22:34 +04:00
|
|
|
#define G(L) (L->l_G)
|
2001-01-19 16:20:30 +03:00
|
|
|
|
|
|
|
|
2002-10-26 00:05:28 +04:00
|
|
|
/*
|
2014-07-18 16:17:54 +04:00
|
|
|
** Union of all collectable objects (only for conversions)
|
2002-10-26 00:05:28 +04:00
|
|
|
*/
|
2014-07-17 21:09:50 +04:00
|
|
|
union GCUnion {
|
|
|
|
GCObject gc; /* common header */
|
2014-07-18 17:36:14 +04:00
|
|
|
struct TString ts;
|
2014-07-18 18:46:47 +04:00
|
|
|
struct Udata u;
|
2002-10-26 00:05:28 +04:00
|
|
|
union Closure cl;
|
|
|
|
struct Table h;
|
|
|
|
struct Proto p;
|
|
|
|
struct lua_State th; /* thread */
|
2017-04-11 21:41:09 +03:00
|
|
|
struct UpVal upv;
|
2002-10-26 00:05:28 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-07-17 21:09:50 +04:00
|
|
|
#define cast_u(o) cast(union GCUnion *, (o))
|
|
|
|
|
2002-11-13 14:32:26 +03:00
|
|
|
/* macros to convert a GCObject into a specific value */
|
2014-07-18 17:36:14 +04:00
|
|
|
#define gco2ts(o) \
|
2014-07-17 21:27:49 +04:00
|
|
|
check_exp(novariant((o)->tt) == LUA_TSTRING, &((cast_u(o))->ts))
|
2020-01-31 17:09:53 +03:00
|
|
|
#define gco2u(o) check_exp((o)->tt == LUA_VUSERDATA, &((cast_u(o))->u))
|
|
|
|
#define gco2lcl(o) check_exp((o)->tt == LUA_VLCL, &((cast_u(o))->cl.l))
|
|
|
|
#define gco2ccl(o) check_exp((o)->tt == LUA_VCCL, &((cast_u(o))->cl.c))
|
2012-01-21 02:05:50 +04:00
|
|
|
#define gco2cl(o) \
|
2014-07-17 21:27:49 +04:00
|
|
|
check_exp(novariant((o)->tt) == LUA_TFUNCTION, &((cast_u(o))->cl))
|
2020-01-31 17:09:53 +03:00
|
|
|
#define gco2t(o) check_exp((o)->tt == LUA_VTABLE, &((cast_u(o))->h))
|
|
|
|
#define gco2p(o) check_exp((o)->tt == LUA_VPROTO, &((cast_u(o))->p))
|
|
|
|
#define gco2th(o) check_exp((o)->tt == LUA_VTHREAD, &((cast_u(o))->th))
|
|
|
|
#define gco2upv(o) check_exp((o)->tt == LUA_VUPVAL, &((cast_u(o))->upv))
|
2014-07-17 21:09:50 +04:00
|
|
|
|
2002-11-13 14:32:26 +03:00
|
|
|
|
2018-02-25 15:43:52 +03:00
|
|
|
/*
|
|
|
|
** macro to convert a Lua object into a GCObject
|
|
|
|
** (The access to 'tt' tries to ensure that 'v' is actually a Lua object.)
|
|
|
|
*/
|
|
|
|
#define obj2gco(v) check_exp((v)->tt >= LUA_TSTRING, &(cast_u(v)->gc))
|
2014-07-18 16:17:54 +04:00
|
|
|
|
2002-11-13 14:32:26 +03:00
|
|
|
|
2010-12-20 22:40:07 +03:00
|
|
|
/* actual number of total bytes allocated */
|
2015-07-04 19:33:17 +03:00
|
|
|
#define gettotalbytes(g) cast(lu_mem, (g)->totalbytes + (g)->GCdebt)
|
2010-12-20 22:40:07 +03:00
|
|
|
|
|
|
|
LUAI_FUNC void luaE_setdebt (global_State *g, l_mem debt);
|
2005-04-25 23:24:10 +04:00
|
|
|
LUAI_FUNC void luaE_freethread (lua_State *L, lua_State *L1);
|
2017-11-07 16:25:26 +03:00
|
|
|
LUAI_FUNC CallInfo *luaE_extendCI (lua_State *L);
|
|
|
|
LUAI_FUNC void luaE_freeCI (lua_State *L);
|
|
|
|
LUAI_FUNC void luaE_shrinkCI (lua_State *L);
|
2018-12-27 19:32:29 +03:00
|
|
|
LUAI_FUNC void luaE_enterCcall (lua_State *L);
|
2019-03-14 21:30:54 +03:00
|
|
|
LUAI_FUNC void luaE_warning (lua_State *L, const char *msg, int tocont);
|
2019-08-16 15:51:54 +03:00
|
|
|
LUAI_FUNC void luaE_warnerror (lua_State *L, const char *where);
|
2018-12-27 19:32:29 +03:00
|
|
|
|
2009-04-17 18:28:06 +04:00
|
|
|
|
2019-06-12 16:31:38 +03:00
|
|
|
#define luaE_exitCcall(L) ((L)->nCcalls++)
|
2002-01-11 23:26:52 +03:00
|
|
|
|
1997-11-19 20:31:19 +03:00
|
|
|
#endif
|
1999-02-04 20:47:59 +03:00
|
|
|
|