diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2009-02-18 11:52:51 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2009-02-18 11:52:51 -0300 |
commit | 81ede6bfcedb9304974110e00a2a4ba301afb4f7 (patch) | |
tree | 581b80af39cf89fe25f0049be3236a76fcffea24 /ltests.c | |
parent | 2b579b4b83f7ebc527089fcb5f18b8531858609c (diff) | |
download | lua-81ede6bfcedb9304974110e00a2a4ba301afb4f7.tar.gz lua-81ede6bfcedb9304974110e00a2a4ba301afb4f7.tar.bz2 lua-81ede6bfcedb9304974110e00a2a4ba301afb4f7.zip |
using light userdata to represent "remote" states
Diffstat (limited to 'ltests.c')
-rw-r--r-- | ltests.c | 22 |
1 files changed, 14 insertions, 8 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ltests.c,v 2.55 2008/08/26 13:27:42 roberto Exp roberto $ | 2 | ** $Id: ltests.c,v 2.56 2008/10/28 12:54:25 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 | */ |
@@ -728,13 +728,20 @@ static int newstate (lua_State *L) { | |||
728 | lua_Alloc f = lua_getallocf(L, &ud); | 728 | lua_Alloc f = lua_getallocf(L, &ud); |
729 | lua_State *L1 = lua_newstate(f, ud); | 729 | lua_State *L1 = lua_newstate(f, ud); |
730 | if (L1) | 730 | if (L1) |
731 | lua_pushinteger(L, (unsigned long)L1); | 731 | lua_pushlightuserdata(L, L1); |
732 | else | 732 | else |
733 | lua_pushnil(L); | 733 | lua_pushnil(L); |
734 | return 1; | 734 | return 1; |
735 | } | 735 | } |
736 | 736 | ||
737 | 737 | ||
738 | static lua_State *getstate (lua_State *L) { | ||
739 | lua_State *L1 = cast(lua_State *, lua_touserdata(L, 1)); | ||
740 | luaL_argcheck(L, L1 != NULL, 1, "state expected"); | ||
741 | return L1; | ||
742 | } | ||
743 | |||
744 | |||
738 | static int loadlib (lua_State *L) { | 745 | static int loadlib (lua_State *L) { |
739 | static const luaL_Reg libs[] = { | 746 | static const luaL_Reg libs[] = { |
740 | {"baselibopen", luaopen_base}, | 747 | {"baselibopen", luaopen_base}, |
@@ -746,21 +753,20 @@ static int loadlib (lua_State *L) { | |||
746 | {"packageopen", luaopen_package}, | 753 | {"packageopen", luaopen_package}, |
747 | {NULL, NULL} | 754 | {NULL, NULL} |
748 | }; | 755 | }; |
749 | lua_State *L1 = cast(lua_State *, | 756 | lua_State *L1 = getstate(L); |
750 | cast(unsigned long, luaL_checknumber(L, 1))); | ||
751 | lua_pushvalue(L1, LUA_GLOBALSINDEX); | 757 | lua_pushvalue(L1, LUA_GLOBALSINDEX); |
752 | luaL_register(L1, NULL, libs); | 758 | luaL_register(L1, NULL, libs); |
753 | return 0; | 759 | return 0; |
754 | } | 760 | } |
755 | 761 | ||
756 | static int closestate (lua_State *L) { | 762 | static int closestate (lua_State *L) { |
757 | lua_State *L1 = cast(lua_State *, cast(unsigned long, luaL_checknumber(L, 1))); | 763 | lua_State *L1 = getstate(L); |
758 | lua_close(L1); | 764 | lua_close(L1); |
759 | return 0; | 765 | return 0; |
760 | } | 766 | } |
761 | 767 | ||
762 | static int doremote (lua_State *L) { | 768 | static int doremote (lua_State *L) { |
763 | lua_State *L1 = cast(lua_State *,cast(unsigned long,luaL_checknumber(L, 1))); | 769 | lua_State *L1 = getstate(L); |
764 | size_t lcode; | 770 | size_t lcode; |
765 | const char *code = luaL_checklstring(L, 2, &lcode); | 771 | const char *code = luaL_checklstring(L, 2, &lcode); |
766 | int status; | 772 | int status; |
@@ -856,8 +862,8 @@ static int testC (lua_State *L) { | |||
856 | char buff[30]; | 862 | char buff[30]; |
857 | lua_State *L1; | 863 | lua_State *L1; |
858 | const char *pc; | 864 | const char *pc; |
859 | if (lua_isnumber(L, 1)) { | 865 | if (lua_isuserdata(L, 1)) { |
860 | L1 = cast(lua_State *,cast(unsigned long,luaL_checknumber(L, 1))); | 866 | L1 = getstate(L); |
861 | pc = luaL_checkstring(L, 2); | 867 | pc = luaL_checkstring(L, 2); |
862 | } | 868 | } |
863 | else { | 869 | else { |