summaryrefslogtreecommitdiff
path: root/lstate.c
diff options
context:
space:
mode:
Diffstat (limited to 'lstate.c')
-rw-r--r--lstate.c21
1 files changed, 12 insertions, 9 deletions
diff --git a/lstate.c b/lstate.c
index 7e264565..f5d5b67c 100644
--- a/lstate.c
+++ b/lstate.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lstate.c,v 1.34 2000/08/28 17:57:04 roberto Exp roberto $ 2** $Id: lstate.c,v 1.35 2000/08/31 13:30:39 roberto Exp roberto $
3** Global State 3** Global State
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -9,7 +9,6 @@
9 9
10#include "lua.h" 10#include "lua.h"
11 11
12#include "lbuiltin.h"
13#include "ldo.h" 12#include "ldo.h"
14#include "lgc.h" 13#include "lgc.h"
15#include "llex.h" 14#include "llex.h"
@@ -20,7 +19,13 @@
20#include "ltm.h" 19#include "ltm.h"
21 20
22 21
23lua_State *lua_newstate (int stacksize, int put_builtin) { 22#ifdef DEBUG
23extern lua_State *lua_state;
24void luaB_opentests (lua_State *L);
25#endif
26
27
28lua_State *lua_newstate (int stacksize) {
24 struct lua_longjmp myErrorJmp; 29 struct lua_longjmp myErrorJmp;
25 lua_State *L = luaM_new(NULL, lua_State); 30 lua_State *L = luaM_new(NULL, lua_State);
26 if (L == NULL) return NULL; /* memory allocation error */ 31 if (L == NULL) return NULL; /* memory allocation error */
@@ -54,8 +59,9 @@ lua_State *lua_newstate (int stacksize, int put_builtin) {
54 luaS_init(L); 59 luaS_init(L);
55 luaX_init(L); 60 luaX_init(L);
56 luaT_init(L); 61 luaT_init(L);
57 if (put_builtin) 62#ifdef DEBUG
58 luaB_predefine(L); 63 luaB_opentests(L);
64#endif
59 L->GCthreshold = L->nblocks*4; 65 L->GCthreshold = L->nblocks*4;
60 L->errorJmp = NULL; 66 L->errorJmp = NULL;
61 return L; 67 return L;
@@ -67,10 +73,6 @@ lua_State *lua_newstate (int stacksize, int put_builtin) {
67} 73}
68 74
69 75
70#ifdef DEBUG
71extern lua_State *lua_state;
72#endif
73
74void lua_close (lua_State *L) { 76void lua_close (lua_State *L) {
75 luaC_collect(L, 1); /* collect all elements */ 77 luaC_collect(L, 1); /* collect all elements */
76 LUA_ASSERT(L->rootproto == NULL, "list should be empty"); 78 LUA_ASSERT(L->rootproto == NULL, "list should be empty");
@@ -83,6 +85,7 @@ void lua_close (lua_State *L) {
83 luaM_free(L, L->Mbuffer); 85 luaM_free(L, L->Mbuffer);
84 LUA_ASSERT(L->nblocks == 0, "wrong count for nblocks"); 86 LUA_ASSERT(L->nblocks == 0, "wrong count for nblocks");
85 luaM_free(L, L); 87 luaM_free(L, L);
88 LUA_ASSERT(L->Cbase == L->stack, "stack not empty");
86 LUA_ASSERT(L != lua_state || memdebug_numblocks == 0, "memory leak!"); 89 LUA_ASSERT(L != lua_state || memdebug_numblocks == 0, "memory leak!");
87 LUA_ASSERT(L != lua_state || memdebug_total == 0,"memory leak!"); 90 LUA_ASSERT(L != lua_state || memdebug_total == 0,"memory leak!");
88} 91}