diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2001-02-02 13:13:05 -0200 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2001-02-02 13:13:05 -0200 |
| commit | 426d3e43bdec4b1ab2b0aed1844396c27f64872f (patch) | |
| tree | 659b73e1e9720fb85c66a481b476c96671eef734 /ltests.c | |
| parent | 8823f371a2a63f634121a0c16cb1d02e5ce9f5c5 (diff) | |
| download | lua-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.c | 23 |
1 files changed, 19 insertions, 4 deletions
| @@ -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 | ||
| 31 | void 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 | ||
| 37 | lua_State *lua_state = NULL; | ||
| 38 | |||
| 39 | int islocked = 0; | ||
| 40 | |||
| 39 | 41 | ||
| 40 | 42 | ||
| 41 | static void setnameval (lua_State *L, const char *name, int val) { | 43 | static void setnameval (lua_State *L, const char *name, int val) { |
| @@ -279,6 +281,7 @@ static int udataval (lua_State *L) { | |||
| 279 | static int doonnewstack (lua_State *L) { | 281 | static 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 | ||
| 289 | static int newstate (lua_State *L) { | 292 | static 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) { | |||
| 311 | static int closestate (lua_State *L) { | 316 | static 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 | ||
| 554 | void luaB_opentests (lua_State *L) { | 560 | void 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 |
