RetroArch
lstate.h
Go to the documentation of this file.
1 /*
2 ** $Id: lstate.h,v 2.133.1.1 2017/04/19 17:39:34 roberto Exp $
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 /*
18 
19 ** Some notes about garbage-collected objects: All objects in Lua must
20 ** be kept somehow accessible until being freed, so all objects always
21 ** belong to one (and only one) of these lists, using field 'next' of
22 ** the 'CommonHeader' for the link:
23 **
24 ** 'allgc': all objects not marked for finalization;
25 ** 'finobj': all objects marked for finalization;
26 ** 'tobefnz': all objects ready to be finalized;
27 ** 'fixedgc': all objects that are not to be collected (currently
28 ** only small strings, such as reserved words).
29 **
30 ** Moreover, there is another set of lists that control gray objects.
31 ** These lists are linked by fields 'gclist'. (All objects that
32 ** can become gray have such a field. The field is not the same
33 ** in all objects, but it always has this name.) Any gray object
34 ** must belong to one of these lists, and all objects in these lists
35 ** must be gray:
36 **
37 ** 'gray': regular gray objects, still waiting to be visited.
38 ** 'grayagain': objects that must be revisited at the atomic phase.
39 ** That includes
40 ** - black objects got in a write barrier;
41 ** - all kinds of weak tables during propagation phase;
42 ** - all threads.
43 ** 'weak': tables with weak values to be cleared;
44 ** 'ephemeron': ephemeron tables with white->white entries;
45 ** 'allweak': tables with weak keys and/or weak values to be cleared.
46 ** The last three lists are used only during the atomic phase.
47 
48 */
49 
50 
51 struct lua_longjmp; /* defined in ldo.c */
52 
53 
54 /*
55 ** Atomic type (relative to signals) to better ensure that 'lua_sethook'
56 ** is thread safe
57 */
58 #if !defined(l_signalT)
59 #include <signal.h>
60 #define l_signalT sig_atomic_t
61 #endif
62 
63 
64 /* extra stack space to handle TM calls and some other extras */
65 #define EXTRA_STACK 5
66 
67 
68 #define BASIC_STACK_SIZE (2*LUA_MINSTACK)
69 
70 
71 /* kinds of Garbage Collection */
72 #define KGC_NORMAL 0
73 #define KGC_EMERGENCY 1 /* gc was forced by an allocation failure */
74 
75 
76 typedef struct stringtable {
78  int nuse; /* number of elements */
79  int size;
80 } stringtable;
81 
82 
83 /*
84 ** Information about a call.
85 ** When a thread yields, 'func' is adjusted to pretend that the
86 ** top function has only the yielded values in its stack; in that
87 ** case, the actual 'func' value is saved in field 'extra'.
88 ** When a function calls another with a continuation, 'extra' keeps
89 ** the function index so that, in case of errors, the continuation
90 ** function can be called with the correct top.
91 */
92 typedef struct CallInfo {
93  StkId func; /* function index in the stack */
94  StkId top; /* top for this function */
95  struct CallInfo *previous, *next; /* dynamic call link */
96  union {
97  struct { /* only for Lua functions */
98  StkId base; /* base for this function */
100  } l;
101  struct { /* only for C functions */
102  lua_KFunction k; /* continuation in case of yields */
103  ptrdiff_t old_errfunc;
104  lua_KContext ctx; /* context info. in case of yields */
105  } c;
106  } u;
107  ptrdiff_t extra;
108  short nresults; /* expected number of results from this function */
109  unsigned short callstatus;
110 } CallInfo;
111 
112 
113 /*
114 ** Bits in CallInfo status
115 */
116 #define CIST_OAH (1<<0) /* original value of 'allowhook' */
117 #define CIST_LUA (1<<1) /* call is running a Lua function */
118 #define CIST_HOOKED (1<<2) /* call is running a debug hook */
119 #define CIST_FRESH (1<<3) /* call is running on a fresh invocation
120  of luaV_execute */
121 #define CIST_YPCALL (1<<4) /* call is a yieldable protected call */
122 #define CIST_TAIL (1<<5) /* call was tail called */
123 #define CIST_HOOKYIELD (1<<6) /* last hook called yielded */
124 #define CIST_LEQ (1<<7) /* using __lt for __le */
125 #define CIST_FIN (1<<8) /* call is running a finalizer */
126 
127 #define isLua(ci) ((ci)->callstatus & CIST_LUA)
128 
129 /* assume that CIST_OAH has offset 0 and that 'v' is strictly 0/1 */
130 #define setoah(st,v) ((st) = ((st) & ~CIST_OAH) | (v))
131 #define getoah(st) ((st) & CIST_OAH)
132 
133 
134 /*
135 ** 'global state', shared by all threads of this state
136 */
137 typedef struct global_State {
138  lua_Alloc frealloc; /* function to reallocate memory */
139  void *ud; /* auxiliary data to 'frealloc' */
140  l_mem totalbytes; /* number of bytes currently allocated - GCdebt */
141  l_mem GCdebt; /* bytes allocated not yet compensated by the collector */
142  lu_mem GCmemtrav; /* memory traversed by the GC */
143  lu_mem GCestimate; /* an estimate of the non-garbage memory in use */
144  stringtable strt; /* hash table for strings */
146  unsigned int seed; /* randomized seed for hashes */
148  lu_byte gcstate; /* state of garbage collector */
149  lu_byte gckind; /* kind of GC running */
150  lu_byte gcrunning; /* true if GC is running */
151  GCObject *allgc; /* list of all collectable objects */
152  GCObject **sweepgc; /* current position of sweep in list */
153  GCObject *finobj; /* list of collectable objects with finalizers */
154  GCObject *gray; /* list of gray objects */
155  GCObject *grayagain; /* list of objects to be traversed atomically */
156  GCObject *weak; /* list of tables with weak values */
157  GCObject *ephemeron; /* list of ephemeron tables (weak keys) */
158  GCObject *allweak; /* list of all-weak tables */
159  GCObject *tobefnz; /* list of userdata to be GC */
160  GCObject *fixedgc; /* list of objects not to be collected */
161  struct lua_State *twups; /* list of threads with open upvalues */
162  unsigned int gcfinnum; /* number of finalizers to call in each GC step */
163  int gcpause; /* size of pause between successive GCs */
164  int gcstepmul; /* GC 'granularity' */
165  lua_CFunction panic; /* to be called in unprotected errors */
167  const lua_Number *version; /* pointer to version number */
168  TString *memerrmsg; /* memory-error message */
169  TString *tmname[TM_N]; /* array with tag-method names */
170  struct Table *mt[LUA_NUMTAGS]; /* metatables for basic types */
171  TString *strcache[STRCACHE_N][STRCACHE_M]; /* cache for strings in API */
172 } global_State;
173 
174 
175 /*
176 ** 'per thread' state
177 */
178 struct lua_State {
180  unsigned short nci; /* number of items in 'ci' list */
182  StkId top; /* first free slot in the stack */
184  CallInfo *ci; /* call info for current function */
185  const Instruction *oldpc; /* last pc traced */
186  StkId stack_last; /* last free slot in the stack */
187  StkId stack; /* stack base */
188  UpVal *openupval; /* list of open upvalues in this stack */
190  struct lua_State *twups; /* list of threads with open upvalues */
191  struct lua_longjmp *errorJmp; /* current error recover point */
192  CallInfo base_ci; /* CallInfo for first level (C calling Lua) */
193  volatile lua_Hook hook;
194  ptrdiff_t errfunc; /* current error handling function (stack index) */
198  unsigned short nny; /* number of non-yieldable calls in stack */
199  unsigned short nCcalls; /* number of nested C calls */
202 };
203 
204 
205 #define G(L) (L->l_G)
206 
207 
208 /*
209 ** Union of all collectable objects (only for conversions)
210 */
211 union GCUnion {
212  GCObject gc; /* common header */
213  struct TString ts;
214  struct Udata u;
215  union Closure cl;
216  struct Table h;
217  struct Proto p;
218  struct lua_State th; /* thread */
219 };
220 
221 
222 #define cast_u(o) cast(union GCUnion *, (o))
223 
224 /* macros to convert a GCObject into a specific value */
225 #define gco2ts(o) \
226  check_exp(novariant((o)->tt) == LUA_TSTRING, &((cast_u(o))->ts))
227 #define gco2u(o) check_exp((o)->tt == LUA_TUSERDATA, &((cast_u(o))->u))
228 #define gco2lcl(o) check_exp((o)->tt == LUA_TLCL, &((cast_u(o))->cl.l))
229 #define gco2ccl(o) check_exp((o)->tt == LUA_TCCL, &((cast_u(o))->cl.c))
230 #define gco2cl(o) \
231  check_exp(novariant((o)->tt) == LUA_TFUNCTION, &((cast_u(o))->cl))
232 #define gco2t(o) check_exp((o)->tt == LUA_TTABLE, &((cast_u(o))->h))
233 #define gco2p(o) check_exp((o)->tt == LUA_TPROTO, &((cast_u(o))->p))
234 #define gco2th(o) check_exp((o)->tt == LUA_TTHREAD, &((cast_u(o))->th))
235 
236 
237 /* macro to convert a Lua object into a GCObject */
238 #define obj2gco(v) \
239  check_exp(novariant((v)->tt) < LUA_TDEADKEY, (&(cast_u(v)->gc)))
240 
241 
242 /* actual number of total bytes allocated */
243 #define gettotalbytes(g) cast(lu_mem, (g)->totalbytes + (g)->GCdebt)
244 
250 
251 
252 #endif
253 
struct lua_State th
Definition: lstate.h:218
void(* lua_Hook)(lua_State *L, lua_Debug *ar)
Definition: lua.h:421
#define STRCACHE_N
Definition: llimits.h:198
Definition: ltm.h:43
GCObject * gclist
Definition: lstate.h:189
GCObject ** sweepgc
Definition: lstate.h:152
struct Table * mt[LUA_NUMTAGS]
Definition: lstate.h:170
CallInfo base_ci
Definition: lstate.h:192
int size
Definition: lstate.h:79
Definition: lobject.h:113
unsigned short nci
Definition: lstate.h:180
GCObject * tobefnz
Definition: lstate.h:159
GCObject * grayagain
Definition: lstate.h:155
GCObject * gray
Definition: lstate.h:154
LUA_KCONTEXT lua_KContext
Definition: lua.h:99
struct lua_State * twups
Definition: lstate.h:190
struct stringtable stringtable
StkId base
Definition: lstate.h:98
LUAI_FUNC CallInfo * luaE_extendCI(lua_State *L)
Definition: lstate.c:108
struct CallInfo::@108::@109 l
LUA_NUMBER lua_Number
Definition: lua.h:89
stringtable strt
Definition: lstate.h:144
TString * strcache[STRCACHE_N][STRCACHE_M]
Definition: lstate.h:171
TString ** hash
Definition: lstate.h:77
Definition: lobject.h:346
ptrdiff_t old_errfunc
Definition: lstate.h:103
struct TString ts
Definition: lstate.h:213
StkId stack
Definition: lstate.h:187
#define LUAI_FUNC
Definition: luaconf.h:282
unsigned int gcfinnum
Definition: lstate.h:162
long l_mem
Definition: llimits.h:30
Compilador Desconocido Dispositivo desconectado del puerto El archivo ya existe Guardándolo en el búfer de respaldo Conexión obtenida Dirección pública Poniendo disco en bandeja As dejado el juego Se ha unido con el dispositivo de entrada *s *s se ha unido como jugador u Una conexión de netplay probablemente no este usando RetroArch o esté usando una versión antigua de RetroArch use la misma versión use la misma versión Este núcleo no soporta juego en red entre diferentes sistemas Contraseña incorrecta Un cliente de juego en red se ha desconectado No tienes permiso para jugar El dispositivo de entrada pedido no esta disponible Cliente de juego en red s pausado Dar a los núcleos renderizados por hardware un contexto privado Evita tener que asumir cambios en el estado del hardware entre cuadros Ajusta la apariencia del menú Mejora el rendimiento a costa de la latencia y posiblemente algunos tirones Usar solo si no puede obtener máxima velocidad de otra manera Auto detectar Capacidades Conectando al puerto Lo no Contraseña Nombre de usuario Fin de la lista Lista de logros Continuar usando el modo Hardcore de logros Escanear Contenido Importar contenido Preguntar Bloquear frames Controlador de Audio Activar audio Turbo Zona Muerta Variación máxima de sincronía de audio Frecuencia de muestreo de Control de frecuencia dinámico Audio Volumen de WASAPI Mode Exclusivo WASAPI Tamaño del búfer compartido Cargar autom archivos de personalización Cargar Shaders automáticamente Confirmar Salir Desplazar hacia arriba Mostrar teclado Controles básicos del menú Información Desplazar hacia arriba Mostrar teclado No sobrescribir SaveRAM al cargar URL de recursos del Buildbot Permitir cámara Truco Iniciar búsqueda de trucos Archivo de trucos Cargar archivo de Cargar archivo de Guardar archivo de trucos como Descripción Tablas de clasificación Logros Bloqueado Probar logros No oficiales Desbloqueado Logros modo informativo Cerrar Cargar configuración Guardar configuración al salir Base de datos Tamaño del historial Menú rápido Descargas Contadores de núcleo Información del núcleo Categorías Nombre del núcleo Permisos Fabricante del sistema Controles Instalar or Restaurar un núcleo Núcleo instalado exitosamente Núcleo Extraer automáticamente el archivo descargado Actualizador de núcleos Arquitectura de Núcleos de Cursor Relación personalizada Seleccionar bases de datos Favoritos< Predeterminada > No se ha encontrado la carpeta Abrir Cerrar la bandeja de discos Índice de disco No importa Descargar núcleo Forzar DPI Controladores Chequear si falta Firmware antes de cargar Fondos de pantalla dinámicos Color de resaltado del menú Desactivado Favoritos Incluir detalles de memoria Sincronizar Velocidad de frames Usar opciones de núcleo para cada juego si existen Archivo de opciones del juego Solucionar problemas de Audio Video Controles básicos del menú Cargando contenido ¿Qué es un núcleo Historial Imágenes Información Todos controlan el menú Analógico izq Analógico izq Analógico izq Y Analógico izq Analógico der X Analógico der Analógico der Y Analógico der Activar Auto configuración Asignar todo Tiempo limite para asignar Ocultar descripciones de entrada sin asignar de los núcleo Indice de dispositivo Indice de ratón Ciclo de trabajo Activar mapeo de Teclado Mando Botón D pad ABAJO Botón Botón L1(LB)" ) MSG_HASH( MENU_ENUM_LABEL_VALUE_INPUT_JOYPAD_LEFT
int hookcount
Definition: lstate.h:197
StkId stack_last
Definition: lstate.h:186
GCObject * allgc
Definition: lstate.h:151
struct CallInfo::@108::@110 c
lua_Alloc frealloc
Definition: lstate.h:138
void *(* lua_Alloc)(void *ud, void *ptr, size_t osize, size_t nsize)
Definition: lua.h:124
lu_mem GCmemtrav
Definition: lstate.h:142
union CallInfo::@108 u
const lua_Number * version
Definition: lstate.h:167
LUAI_FUNC void luaE_freeCI(lua_State *L)
Definition: lstate.c:122
TValue l_registry
Definition: lstate.h:145
StkId func
Definition: lstate.h:93
GCObject * weak
Definition: lstate.h:156
int nuse
Definition: lstate.h:78
struct lua_longjmp * errorJmp
Definition: lstate.h:191
lu_byte status
Definition: lstate.h:181
lua_CFunction panic
Definition: lstate.h:165
int gcstepmul
Definition: lstate.h:164
void * ud
Definition: lstate.h:139
lua_KContext ctx
Definition: lstate.h:104
short nresults
Definition: lstate.h:108
int(* lua_KFunction)(lua_State *L, int status, lua_KContext ctx)
Definition: lua.h:110
UpVal * openupval
Definition: lstate.h:188
l_mem totalbytes
Definition: lstate.h:140
CallInfo * ci
Definition: lstate.h:184
TString * tmname[TM_N]
Definition: lstate.h:169
volatile lua_Hook hook
Definition: lstate.h:193
CommonHeader
Definition: lstate.h:179
Definition: lstate.h:76
unsigned long lu_mem
Definition: llimits.h:29
#define LUA_NUMTAGS
Definition: lua.h:74
struct lua_State * mainthread
Definition: lstate.h:166
l_mem GCdebt
Definition: lstate.h:141
unsigned short callstatus
Definition: lstate.h:109
GCObject * fixedgc
Definition: lstate.h:160
GLfloat GLfloat p
Definition: glext.h:9809
const Instruction * savedpc
Definition: lstate.h:99
lu_mem GCestimate
Definition: lstate.h:143
GCObject * allweak
Definition: lstate.h:158
unsigned char lu_byte
Definition: llimits.h:35
lu_byte gckind
Definition: lstate.h:149
LUAI_FUNC void luaE_freethread(lua_State *L, lua_State *L1)
Definition: lstate.c:285
l_signalT hookmask
Definition: lstate.h:200
Definition: lstate.h:137
Definition: lobject.h:460
struct CallInfo CallInfo
Definition: lobject.h:407
LUAI_FUNC void luaE_setdebt(global_State *g, l_mem debt)
Definition: lstate.c:98
GLboolean GLboolean g
Definition: glext.h:6844
StkId top
Definition: lstate.h:182
StkId top
Definition: lstate.h:94
lua_KFunction k
Definition: lstate.h:102
GCObject gc
Definition: lstate.h:212
#define l_signalT
Definition: lstate.h:60
Definition: lstate.h:211
struct Udata u
Definition: lstate.h:214
struct lua_State * twups
Definition: lstate.h:161
#define STRCACHE_M
Definition: llimits.h:199
Ιστορικό Εικόνα Πληροφορίες Όλοι Οι Χρήστες Χειρίζονται Το Μενού Αριστερό Αναλογικό Αριστερό Αναλογικό Αριστερό Αναλογικό Y Αριστερό Αναλογικό Δεξί Αναλογικό X Δεξί Αναλογικό Δεξί Αναλογικό Y Δεξί Αναλογικό Σκανδάλη Όπλου Όπλο Aux A Όπλο Aux C Όπλο Select Όπλο D pad Κάτω Όπλο D pad Δεξιά Νεκρή Ζώνη Αναλογικού Σύνδεση Όλων Λήξη Χρόνου Σύνδεσης Hide Unbound Core Input Descriptors Κατάλογος Συσκευών Κατάλογος Ποντικιού Duty Cycle Keyboard Gamepad Mapping Enable Κουμπί D pad κάτω Κουμπί Κουμπί L(πίσω)" ) MSG_HASH( MENU_ENUM_LABEL_VALUE_INPUT_JOYPAD_LEFT
ptrdiff_t extra
Definition: lstate.h:107
unsigned short nny
Definition: lstate.h:198
struct global_State global_State
Definition: lstate.h:92
unsigned int seed
Definition: lstate.h:146
int(* lua_CFunction)(lua_State *L)
Definition: lua.h:105
union Closure cl
Definition: lstate.h:215
unsigned short nCcalls
Definition: lstate.h:199
unsigned long Instruction
Definition: llimits.h:165
global_State * l_G
Definition: lstate.h:183
GLfloat GLfloat GLfloat GLfloat h
Definition: glext.h:8390
struct CallInfo * previous
Definition: lstate.h:95
TString * memerrmsg
Definition: lstate.h:168
Definition: lobject.h:497
Definition: lfunc.h:35
const Instruction * oldpc
Definition: lstate.h:185
struct CallInfo * next
Definition: lstate.h:95
int gcpause
Definition: lstate.h:163
int stacksize
Definition: lstate.h:195
lu_byte allowhook
Definition: lstate.h:201
Definition: lstate.h:178
Definition: ldo.c:84
GCObject * ephemeron
Definition: lstate.h:157
ptrdiff_t errfunc
Definition: lstate.h:194
int basehookcount
Definition: lstate.h:196
LUAI_FUNC void luaE_shrinkCI(lua_State *L)
Definition: lstate.c:137
lu_byte gcrunning
Definition: lstate.h:150
Definition: lobject.h:303
lu_byte gcstate
Definition: lstate.h:148
Definition: lobject.h:85
lu_byte currentwhite
Definition: lstate.h:147
GCObject * finobj
Definition: lstate.h:153