aboutsummaryrefslogtreecommitdiff
path: root/ltests.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2001-02-02 13:13:05 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2001-02-02 13:13:05 -0200
commit426d3e43bdec4b1ab2b0aed1844396c27f64872f (patch)
tree659b73e1e9720fb85c66a481b476c96671eef734 /ltests.c
parent8823f371a2a63f634121a0c16cb1d02e5ce9f5c5 (diff)
downloadlua-426d3e43bdec4b1ab2b0aed1844396c27f64872f.tar.gz
lua-426d3e43bdec4b1ab2b0aed1844396c27f64872f.tar.bz2
lua-426d3e43bdec4b1ab2b0aed1844396c27f64872f.zip
lock/unlock may use L + better structure for internal debug stuff
Diffstat (limited to 'ltests.c')
-rw-r--r--ltests.c23
1 files changed, 19 insertions, 4 deletions
diff --git a/ltests.c b/ltests.c
index 12a33cfe..814102ff 100644
--- a/ltests.c
+++ b/ltests.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ltests.c,v 1.60 2001/01/29 17:16:58 roberto Exp roberto $ 2** $Id: ltests.c,v 1.61 2001/02/01 16:03:38 roberto Exp roberto $
3** Internal Module for Debugging of the Lua Implementation 3** Internal Module for Debugging of the Lua Implementation
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -28,14 +28,16 @@
28#include "lualib.h" 28#include "lualib.h"
29 29
30 30
31void luaB_opentests (lua_State *L);
32
33 31
34/* 32/*
35** The whole module only makes sense with LUA_DEBUG on 33** The whole module only makes sense with LUA_DEBUG on
36*/ 34*/
37#ifdef LUA_DEBUG 35#ifdef LUA_DEBUG
38 36
37lua_State *lua_state = NULL;
38
39int islocked = 0;
40
39 41
40 42
41static void setnameval (lua_State *L, const char *name, int val) { 43static void setnameval (lua_State *L, const char *name, int val) {
@@ -279,6 +281,7 @@ static int udataval (lua_State *L) {
279static int doonnewstack (lua_State *L) { 281static int doonnewstack (lua_State *L) {
280 lua_State *L1 = lua_open(L, luaL_check_int(L, 1)); 282 lua_State *L1 = lua_open(L, luaL_check_int(L, 1));
281 if (L1 == NULL) return 0; 283 if (L1 == NULL) return 0;
284 *((int **)L1) = &islocked; /* initialize the lock */
282 lua_dostring(L1, luaL_check_string(L, 2)); 285 lua_dostring(L1, luaL_check_string(L, 2));
283 lua_pushnumber(L, 1); 286 lua_pushnumber(L, 1);
284 lua_close(L1); 287 lua_close(L1);
@@ -288,8 +291,10 @@ static int doonnewstack (lua_State *L) {
288 291
289static int newstate (lua_State *L) { 292static int newstate (lua_State *L) {
290 lua_State *L1 = lua_open(NULL, luaL_check_int(L, 1)); 293 lua_State *L1 = lua_open(NULL, luaL_check_int(L, 1));
291 if (L1) 294 if (L1) {
295 *((int **)L1) = &islocked; /* initialize the lock */
292 lua_pushuserdata(L, L1); 296 lua_pushuserdata(L, L1);
297 }
293 else 298 else
294 lua_pushnil(L); 299 lua_pushnil(L);
295 return 1; 300 return 1;
@@ -311,6 +316,7 @@ static int loadlib (lua_State *L) {
311static int closestate (lua_State *L) { 316static int closestate (lua_State *L) {
312 luaL_checktype(L, 1, LUA_TUSERDATA); 317 luaL_checktype(L, 1, LUA_TUSERDATA);
313 lua_close((lua_State *)lua_touserdata(L, 1)); 318 lua_close((lua_State *)lua_touserdata(L, 1));
319 LUA_UNLOCK(L); /* close cannot unlock that */
314 return 0; 320 return 0;
315} 321}
316 322
@@ -552,6 +558,9 @@ static const struct luaL_reg tests_funcs[] = {
552 558
553 559
554void luaB_opentests (lua_State *L) { 560void luaB_opentests (lua_State *L) {
561 *((int **)L) = &islocked; /* init lock */
562 lua_state = L; /* keep first state to be opened */
563 /* open lib in a new table */
555 lua_newtable(L); 564 lua_newtable(L);
556 lua_getglobals(L); 565 lua_getglobals(L);
557 lua_pushvalue(L, -2); 566 lua_pushvalue(L, -2);
@@ -559,6 +568,12 @@ void luaB_opentests (lua_State *L) {
559 luaL_openl(L, tests_funcs); /* open functions inside new table */ 568 luaL_openl(L, tests_funcs); /* open functions inside new table */
560 lua_setglobals(L); /* restore old table of globals */ 569 lua_setglobals(L); /* restore old table of globals */
561 lua_setglobal(L, "T"); /* set new table as global T */ 570 lua_setglobal(L, "T"); /* set new table as global T */
571 /* open other libraries */
572 lua_baselibopen(L);
573 lua_iolibopen(L);
574 lua_strlibopen(L);
575 lua_mathlibopen(L);
576 lua_dblibopen(L);
562} 577}
563 578
564#endif 579#endif