1997-11-20 01:31:19 +08:00
|
|
|
/*
|
1999-04-14 03:30:51 +08:00
|
|
|
** $Id: lstate.c,v 1.9 1999/02/25 15:17:01 roberto Exp roberto $
|
1997-11-20 01:31:19 +08:00
|
|
|
** Global State
|
|
|
|
** See Copyright Notice in lua.h
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include "lbuiltin.h"
|
|
|
|
#include "ldo.h"
|
1997-12-02 04:31:25 +08:00
|
|
|
#include "lfunc.h"
|
|
|
|
#include "lgc.h"
|
1997-11-20 01:31:19 +08:00
|
|
|
#include "llex.h"
|
|
|
|
#include "lmem.h"
|
|
|
|
#include "lstate.h"
|
|
|
|
#include "lstring.h"
|
|
|
|
#include "ltable.h"
|
|
|
|
#include "ltm.h"
|
|
|
|
|
|
|
|
|
1998-06-03 04:37:04 +08:00
|
|
|
lua_State *lua_state = NULL;
|
1997-11-20 01:31:19 +08:00
|
|
|
|
|
|
|
|
|
|
|
void lua_open (void)
|
|
|
|
{
|
|
|
|
if (lua_state) return;
|
1998-06-03 04:37:04 +08:00
|
|
|
lua_state = luaM_new(lua_State);
|
1997-11-20 01:31:19 +08:00
|
|
|
L->Cstack.base = 0;
|
|
|
|
L->Cstack.lua2C = 0;
|
|
|
|
L->Cstack.num = 0;
|
|
|
|
L->errorJmp = NULL;
|
1999-04-14 03:30:51 +08:00
|
|
|
L->Mbuffer = NULL;
|
|
|
|
L->Mbuffbase = 0;
|
|
|
|
L->Mbuffsize = 0;
|
|
|
|
L->Mbuffnext = 0;
|
|
|
|
L->numCblocks = 0;
|
1999-02-05 01:47:59 +08:00
|
|
|
L->debug = 0;
|
|
|
|
L->callhook = NULL;
|
|
|
|
L->linehook = NULL;
|
1997-11-20 01:31:19 +08:00
|
|
|
L->rootproto.next = NULL;
|
|
|
|
L->rootproto.marked = 0;
|
|
|
|
L->rootcl.next = NULL;
|
|
|
|
L->rootcl.marked = 0;
|
|
|
|
L->rootglobal.next = NULL;
|
|
|
|
L->rootglobal.marked = 0;
|
|
|
|
L->roottable.next = NULL;
|
|
|
|
L->roottable.marked = 0;
|
1999-04-14 03:30:51 +08:00
|
|
|
L->IMtable = NULL;
|
1997-11-20 01:31:19 +08:00
|
|
|
L->refArray = NULL;
|
|
|
|
L->refSize = 0;
|
|
|
|
L->GCthreshold = GARBAGE_BLOCK;
|
|
|
|
L->nblocks = 0;
|
|
|
|
luaD_init();
|
|
|
|
luaS_init();
|
|
|
|
luaX_init();
|
|
|
|
luaT_init();
|
|
|
|
luaB_predefine();
|
|
|
|
}
|
|
|
|
|
1997-12-02 04:31:25 +08:00
|
|
|
|
|
|
|
void lua_close (void)
|
|
|
|
{
|
|
|
|
TaggedString *alludata = luaS_collectudata();
|
|
|
|
L->GCthreshold = MAX_INT; /* to avoid GC during GC */
|
|
|
|
luaC_hashcallIM((Hash *)L->roottable.next); /* GC t.methods for tables */
|
|
|
|
luaC_strcallIM(alludata); /* GC tag methods for userdata */
|
|
|
|
luaD_gcIM(&luaO_nilobject); /* GC tag method for nil (signal end of GC) */
|
|
|
|
luaH_free((Hash *)L->roottable.next);
|
|
|
|
luaF_freeproto((TProtoFunc *)L->rootproto.next);
|
|
|
|
luaF_freeclosure((Closure *)L->rootcl.next);
|
|
|
|
luaS_free(alludata);
|
|
|
|
luaS_freeall();
|
|
|
|
luaM_free(L->stack.stack);
|
|
|
|
luaM_free(L->IMtable);
|
|
|
|
luaM_free(L->refArray);
|
|
|
|
luaM_free(L->Mbuffer);
|
|
|
|
luaM_free(L);
|
|
|
|
L = NULL;
|
1997-12-11 22:48:46 +08:00
|
|
|
#ifdef DEBUG
|
1997-12-02 04:31:25 +08:00
|
|
|
printf("total de blocos: %ld\n", numblocks);
|
|
|
|
printf("total de memoria: %ld\n", totalmem);
|
|
|
|
#endif
|
|
|
|
}
|
1998-06-03 04:37:04 +08:00
|
|
|
|
|
|
|
|