A modern Music Player Daemon based on Rockbox open source high quality audio player
libadwaita audio rust zig deno mpris rockbox mpd
at master 170 lines 5.0 kB view raw
1/* 2** $Id$ 3** Global State 4** See Copyright Notice in lua.h 5*/ 6 7#ifndef lstate_h 8#define lstate_h 9 10#include "lua.h" 11 12#include "lobject.h" 13#include "ltm.h" 14#include "lzio.h" 15 16 17 18struct lua_longjmp; /* defined in ldo.c */ 19 20 21/* table of globals */ 22#define gt(L) (&L->l_gt) 23 24/* registry */ 25#define registry(L) (&G(L)->l_registry) 26 27 28/* extra stack space to handle TM calls and some other extras */ 29#define EXTRA_STACK 5 30 31 32#define BASIC_CI_SIZE 8 33 34#define BASIC_STACK_SIZE (2*LUA_MINSTACK) 35 36 37 38typedef struct stringtable { 39 GCObject **hash; 40 lu_int32 nuse; /* number of elements */ 41 int size; 42} stringtable; 43 44 45/* 46** informations about a call 47*/ 48typedef struct CallInfo { 49 StkId base; /* base for this function */ 50 StkId func; /* function index in the stack */ 51 StkId top; /* top for this function */ 52 const Instruction *savedpc; 53 int nresults; /* expected number of results from this function */ 54 int tailcalls; /* number of tail calls lost under this entry */ 55} CallInfo; 56 57 58 59#define curr_func(L) (clvalue(L->ci->func)) 60#define ci_func(ci) (clvalue((ci)->func)) 61#define f_isLua(ci) (!ci_func(ci)->c.isC) 62#define isLua(ci) (ttisfunction((ci)->func) && f_isLua(ci)) 63 64 65/* 66** `global state', shared by all threads of this state 67*/ 68typedef struct global_State { 69 stringtable strt; /* hash table for strings */ 70 lua_Alloc frealloc; /* function to reallocate memory */ 71 void *ud; /* auxiliary data to `frealloc' */ 72 lu_byte currentwhite; 73 lu_byte gcstate; /* state of garbage collector */ 74 lu_byte gcflags; /* flags for the garbage collector */ 75 int sweepstrgc; /* position of sweep in `strt' */ 76 GCObject *rootgc; /* list of all collectable objects */ 77 GCObject **sweepgc; /* position of sweep in `rootgc' */ 78 GCObject *gray; /* list of gray objects */ 79 GCObject *grayagain; /* list of objects to be traversed atomically */ 80 GCObject *weak; /* list of weak tables (to be cleared) */ 81 GCObject *tmudata; /* last element of list of userdata to be GC */ 82 Mbuffer buff; /* temporary buffer for string concatentation */ 83 lu_mem GCthreshold; 84 lu_mem totalbytes; /* number of bytes currently allocated */ 85 lu_mem estimate; /* an estimate of number of bytes actually in use */ 86 lu_mem gcdept; /* how much GC is `behind schedule' */ 87 int gcpause; /* size of pause between successive GCs */ 88 int gcstepmul; /* GC `granularity' */ 89 lua_CFunction panic; /* to be called in unprotected errors */ 90 TValue l_registry; 91 struct lua_State *mainthread; 92 UpVal uvhead; /* head of double-linked list of all open upvalues */ 93 struct Table *mt[NUM_TAGS]; /* metatables for basic types */ 94 TString *tmname[TM_N]; /* array with tag-method names */ 95} global_State; 96 97 98/* 99** `per thread' state 100*/ 101struct lua_State { 102 CommonHeader; 103 lu_byte status; 104 StkId top; /* first free slot in the stack */ 105 StkId base; /* base of current function */ 106 global_State *l_G; 107 CallInfo *ci; /* call info for current function */ 108 const Instruction *savedpc; /* `savedpc' of current function */ 109 StkId stack_last; /* last free slot in the stack */ 110 StkId stack; /* stack base */ 111 CallInfo *end_ci; /* points after end of ci array*/ 112 CallInfo *base_ci; /* array of CallInfo's */ 113 int stacksize; 114 int size_ci; /* size of array `base_ci' */ 115 unsigned short nCcalls; /* number of nested C calls */ 116 unsigned short baseCcalls; /* nested C calls when resuming coroutine */ 117 lu_byte hookmask; 118 lu_byte allowhook; 119 int basehookcount; 120 int hookcount; 121 lua_Hook hook; 122 TValue l_gt; /* table of globals */ 123 TValue env; /* temporary place for environments */ 124 GCObject *openupval; /* list of open upvalues in this stack */ 125 GCObject *gclist; 126 struct lua_longjmp *errorJmp; /* current error recover point */ 127 ptrdiff_t errfunc; /* current error handling function (stack index) */ 128}; 129 130 131#define G(L) (L->l_G) 132 133 134/* 135** Union of all collectable objects 136*/ 137union GCObject { 138 GCheader gch; 139 union TString ts; 140 union Udata u; 141 union Closure cl; 142 struct Table h; 143 struct Proto p; 144 struct UpVal uv; 145 struct lua_State th; /* thread */ 146}; 147 148 149/* macros to convert a GCObject into a specific value */ 150#define rawgco2ts(o) check_exp((o)->gch.tt == LUA_TSTRING, &((o)->ts)) 151#define gco2ts(o) (&rawgco2ts(o)->tsv) 152#define rawgco2u(o) check_exp((o)->gch.tt == LUA_TUSERDATA, &((o)->u)) 153#define gco2u(o) (&rawgco2u(o)->uv) 154#define gco2cl(o) check_exp((o)->gch.tt == LUA_TFUNCTION, &((o)->cl)) 155#define gco2h(o) check_exp((o)->gch.tt == LUA_TTABLE, &((o)->h)) 156#define gco2p(o) check_exp((o)->gch.tt == LUA_TPROTO, &((o)->p)) 157#define gco2uv(o) check_exp((o)->gch.tt == LUA_TUPVAL, &((o)->uv)) 158#define ngcotouv(o) \ 159 check_exp((o) == NULL || (o)->gch.tt == LUA_TUPVAL, &((o)->uv)) 160#define gco2th(o) check_exp((o)->gch.tt == LUA_TTHREAD, &((o)->th)) 161 162/* macro to convert any Lua object into a GCObject */ 163#define obj2gco(v) (cast(GCObject *, (v))) 164 165 166LUAI_FUNC lua_State *luaE_newthread (lua_State *L); 167LUAI_FUNC void luaE_freethread (lua_State *L, lua_State *L1); 168 169#endif 170