diff options
Diffstat (limited to 'ltests.c')
-rw-r--r-- | ltests.c | 14 |
1 files changed, 11 insertions, 3 deletions
@@ -36,7 +36,7 @@ | |||
36 | #ifdef LUA_DEBUG | 36 | #ifdef LUA_DEBUG |
37 | 37 | ||
38 | 38 | ||
39 | lua_State *lua_state = NULL; | 39 | static lua_State *lua_state = NULL; |
40 | 40 | ||
41 | int islocked = 0; | 41 | int islocked = 0; |
42 | 42 | ||
@@ -374,10 +374,9 @@ static int udataval (lua_State *L) { | |||
374 | 374 | ||
375 | static int doonnewstack (lua_State *L) { | 375 | static int doonnewstack (lua_State *L) { |
376 | lua_State *L1 = lua_newthread(L, luaL_check_int(L, 1)); | 376 | lua_State *L1 = lua_newthread(L, luaL_check_int(L, 1)); |
377 | if (L1 == NULL) return 0; | ||
378 | lua_dostring(L1, luaL_check_string(L, 2)); | 377 | lua_dostring(L1, luaL_check_string(L, 2)); |
379 | lua_pushnumber(L, 1); | 378 | lua_pushnumber(L, 1); |
380 | lua_close(L1); | 379 | lua_closethread(L, L1); |
381 | return 1; | 380 | return 1; |
382 | } | 381 | } |
383 | 382 | ||
@@ -652,6 +651,14 @@ static const struct luaL_reg tests_funcs[] = { | |||
652 | }; | 651 | }; |
653 | 652 | ||
654 | 653 | ||
654 | static void fim (void) { | ||
655 | if (!islocked) | ||
656 | lua_close(lua_state); | ||
657 | lua_assert(memdebug_numblocks == 0); | ||
658 | lua_assert(memdebug_total == 0); | ||
659 | } | ||
660 | |||
661 | |||
655 | void luaB_opentests (lua_State *L) { | 662 | void luaB_opentests (lua_State *L) { |
656 | *cast(int **, L) = &islocked; /* init lock */ | 663 | *cast(int **, L) = &islocked; /* init lock */ |
657 | lua_state = L; /* keep first state to be opened */ | 664 | lua_state = L; /* keep first state to be opened */ |
@@ -663,6 +670,7 @@ void luaB_opentests (lua_State *L) { | |||
663 | luaL_openl(L, tests_funcs); /* open functions inside new table */ | 670 | luaL_openl(L, tests_funcs); /* open functions inside new table */ |
664 | lua_setglobals(L); /* restore old table of globals */ | 671 | lua_setglobals(L); /* restore old table of globals */ |
665 | lua_setglobal(L, "T"); /* set new table as global T */ | 672 | lua_setglobal(L, "T"); /* set new table as global T */ |
673 | atexit(fim); | ||
666 | } | 674 | } |
667 | 675 | ||
668 | #endif | 676 | #endif |