CHDK_DE Vorschauversion  Trunk Rev. 6014
 Alle Datenstrukturen Dateien Funktionen Variablen Typdefinitionen Aufzählungen Aufzählungswerte Makrodefinitionen
lstate.c-Dateireferenz
#include <stddef.h>
#include "lua.h"
#include "ldebug.h"
#include "ldo.h"
#include "lfunc.h"
#include "lgc.h"
#include "llex.h"
#include "lmem.h"
#include "lstate.h"
#include "lstring.h"
#include "ltable.h"
#include "ltm.h"
+ Include-Abhängigkeitsdiagramm für lstate.c:

gehe zum Quellcode dieser Datei

Datenstrukturen

struct  LG
 

Makrodefinitionen

#define lstate_c
 
#define LUA_CORE
 
#define state_size(x)   (sizeof(x) + LUAI_EXTRASPACE)
 
#define fromstate(l)   (cast(lu_byte *, (l)) - LUAI_EXTRASPACE)
 
#define tostate(l)   (cast(lua_State *, cast(lu_byte *, l) + LUAI_EXTRASPACE))
 

Typdefinitionen

typedef struct LG LG
 

Funktionen

static void stack_init (lua_State *L1, lua_State *L)
 
static void freestack (lua_State *L, lua_State *L1)
 
static void f_luaopen (lua_State *L, void *ud)
 
static void preinit_state (lua_State *L, global_State *g)
 
static void close_state (lua_State *L)
 
LUAI_FUNC lua_StateluaE_newthread (lua_State *L)
 
LUAI_FUNC void luaE_freethread (lua_State *L, lua_State *L1)
 
LUA_API lua_Statelua_newstate (lua_Alloc f, void *ud)
 
static void callallgcTM (lua_State *L, void *ud)
 
LUA_API void lua_close (lua_State *L)
 

Makro-Dokumentation

#define fromstate (   l)    (cast(lu_byte *, (l)) - LUAI_EXTRASPACE)

Definiert in Zeile 28 der Datei lstate.c.

#define lstate_c

Definiert in Zeile 10 der Datei lstate.c.

#define LUA_CORE

Definiert in Zeile 11 der Datei lstate.c.

#define state_size (   x)    (sizeof(x) + LUAI_EXTRASPACE)

Definiert in Zeile 27 der Datei lstate.c.

#define tostate (   l)    (cast(lua_State *, cast(lu_byte *, l) + LUAI_EXTRASPACE))

Definiert in Zeile 29 der Datei lstate.c.

Dokumentation der benutzerdefinierten Typen

typedef struct LG LG

Dokumentation der Funktionen

static void callallgcTM ( lua_State L,
void *  ud 
)
static

Definiert in Zeile 193 der Datei lstate.c.

193  {
194  UNUSED(ud);
195  luaC_callGCTM(L); /* call GC metamethods for all udata */
196 }
static void close_state ( lua_State L)
static

Definiert in Zeile 105 der Datei lstate.c.

105  {
106  global_State *g = G(L);
107  luaF_close(L, L->stack); /* close all upvalues for this thread */
108  luaC_freeall(L); /* collect all objects */
109  lua_assert(g->rootgc == obj2gco(L));
110  lua_assert(g->strt.nuse == 0);
111  luaM_freearray(L, G(L)->strt.hash, G(L)->strt.size, TString *);
112  luaZ_freebuffer(L, &g->buff);
113  freestack(L, L);
114  lua_assert(g->totalbytes == sizeof(LG));
115  (*g->frealloc)(g->ud, fromstate(L), state_size(LG), 0);
116 }
static void f_luaopen ( lua_State L,
void *  ud 
)
static

Definiert in Zeile 70 der Datei lstate.c.

70  {
71  global_State *g = G(L);
72  UNUSED(ud);
73  stack_init(L, L); /* init stack */
74  sethvalue(L, gt(L), luaH_new(L, 0, 2)); /* table of globals */
75  sethvalue(L, registry(L), luaH_new(L, 0, 2)); /* registry */
76  luaS_resize(L, MINSTRTABSIZE); /* initial size of string table */
77  luaT_init(L);
78  luaX_init(L);
80  g->GCthreshold = 4*g->totalbytes;
81 }
static void freestack ( lua_State L,
lua_State L1 
)
static

Definiert in Zeile 61 der Datei lstate.c.

61  {
62  luaM_freearray(L, L1->base_ci, L1->size_ci, CallInfo);
63  luaM_freearray(L, L1->stack, L1->stacksize, TValue);
64 }
LUA_API void lua_close ( lua_State L)

Definiert in Zeile 199 der Datei lstate.c.

199  {
200  L = G(L)->mainthread; /* only the main thread can be closed */
201  lua_lock(L);
202  luaF_close(L, L->stack); /* close all upvalues for this thread */
203  luaC_separateudata(L, 1); /* separate udata that have GC metamethods */
204  L->errfunc = 0; /* no error function during GC metamethods */
205  do { /* repeat until no more errors */
206  L->ci = L->base_ci;
207  L->base = L->top = L->ci->base;
208  L->nCcalls = L->baseCcalls = 0;
209  } while (luaD_rawrunprotected(L, callallgcTM, NULL) != 0);
210  lua_assert(G(L)->tmudata == NULL);
212  close_state(L);
213 }
LUA_API lua_State* lua_newstate ( lua_Alloc  f,
void *  ud 
)

Definiert in Zeile 143 der Datei lstate.c.

143  {
144  int i;
145  lua_State *L;
146  global_State *g;
147  void *l = (*f)(ud, NULL, 0, state_size(LG));
148  if (l == NULL) return NULL;
149  L = tostate(l);
150  g = &((LG *)L)->g;
151  L->next = NULL;
152  L->tt = LUA_TTHREAD;
154  L->marked = luaC_white(g);
155  set2bits(L->marked, FIXEDBIT, SFIXEDBIT);
156  preinit_state(L, g);
157  g->frealloc = f;
158  g->ud = ud;
159  g->mainthread = L;
160  g->uvhead.u.l.prev = &g->uvhead;
161  g->uvhead.u.l.next = &g->uvhead;
162  g->GCthreshold = 0; /* mark it as unfinished state */
163  g->strt.size = 0;
164  g->strt.nuse = 0;
165  g->strt.hash = NULL;
166  setnilvalue(registry(L));
167  luaZ_initbuffer(L, &g->buff);
168  g->panic = NULL;
169  g->gcstate = GCSpause;
170  g->rootgc = obj2gco(L);
171  g->sweepstrgc = 0;
172  g->sweepgc = &g->rootgc;
173  g->gray = NULL;
174  g->grayagain = NULL;
175  g->weak = NULL;
176  g->tmudata = NULL;
177  g->totalbytes = sizeof(LG);
178  g->gcpause = LUAI_GCPAUSE;
179  g->gcstepmul = LUAI_GCMUL;
180  g->gcdept = 0;
181  for (i=0; i<NUM_TAGS; i++) g->mt[i] = NULL;
182  if (luaD_rawrunprotected(L, f_luaopen, NULL) != 0) {
183  /* memory allocation error: free partial state */
184  close_state(L);
185  L = NULL;
186  }
187  else
189  return L;
190 }
LUAI_FUNC void luaE_freethread ( lua_State L,
lua_State L1 
)

Definiert in Zeile 134 der Datei lstate.c.

134  {
135  luaF_close(L1, L1->stack); /* close all upvalues for this thread */
136  lua_assert(L1->openupval == NULL);
137  luai_userstatefree(L1);
138  freestack(L, L1);
140 }
LUAI_FUNC lua_State* luaE_newthread ( lua_State L)

Definiert in Zeile 119 der Datei lstate.c.

119  {
121  luaC_link(L, obj2gco(L1), LUA_TTHREAD);
122  preinit_state(L1, G(L));
123  stack_init(L1, L); /* init stack */
124  setobj2n(L, gt(L1), gt(L)); /* share table of globals */
125  L1->hookmask = L->hookmask;
126  L1->basehookcount = L->basehookcount;
127  L1->hook = L->hook;
128  resethookcount(L1);
129  lua_assert(iswhite(obj2gco(L1)));
130  return L1;
131 }
static void preinit_state ( lua_State L,
global_State g 
)
static

Definiert in Zeile 84 der Datei lstate.c.

84  {
85  G(L) = g;
86  L->stack = NULL;
87  L->stacksize = 0;
88  L->errorJmp = NULL;
89  L->hook = NULL;
90  L->hookmask = 0;
91  L->basehookcount = 0;
92  L->allowhook = 1;
93  resethookcount(L);
94  L->openupval = NULL;
95  L->size_ci = 0;
96  L->nCcalls = L->baseCcalls = 0;
97  L->status = 0;
98  L->base_ci = L->ci = NULL;
99  L->savedpc = NULL;
100  L->errfunc = 0;
101  setnilvalue(gt(L));
102 }
static void stack_init ( lua_State L1,
lua_State L 
)
static

Definiert in Zeile 42 der Datei lstate.c.

42  {
43  /* initialize CallInfo array */
45  L1->ci = L1->base_ci;
46  L1->size_ci = BASIC_CI_SIZE;
47  L1->end_ci = L1->base_ci + L1->size_ci - 1;
48  /* initialize stack array */
51  L1->top = L1->stack;
52  L1->stack_last = L1->stack+(L1->stacksize - EXTRA_STACK)-1;
53  /* initialize first ci */
54  L1->ci->func = L1->top;
55  setnilvalue(L1->top++); /* `function' entry for this `ci' */
56  L1->base = L1->ci->base = L1->top;
57  L1->ci->top = L1->top + LUA_MINSTACK;
58 }