diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2001-02-09 17:53:16 -0200 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2001-02-09 17:53:16 -0200 |
| commit | 6875fdc8be9029b1bb29379c59d5409a0df42c10 (patch) | |
| tree | af7d5845b1e209473ecf8ad0f53a188974628b20 /ltests.c | |
| parent | dc17a9cc24a52a298dbfb7ffe8aaad393f7c1bf9 (diff) | |
| download | lua-6875fdc8be9029b1bb29379c59d5409a0df42c10.tar.gz lua-6875fdc8be9029b1bb29379c59d5409a0df42c10.tar.bz2 lua-6875fdc8be9029b1bb29379c59d5409a0df42c10.zip | |
new semantics for pushuserdata (no more different userdatas with same value)
Diffstat (limited to 'ltests.c')
| -rw-r--r-- | ltests.c | 21 |
1 files changed, 16 insertions, 5 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ltests.c,v 1.63 2001/02/06 16:01:29 roberto Exp roberto $ | 2 | ** $Id: ltests.c,v 1.64 2001/02/06 18:18:58 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 | */ |
| @@ -348,11 +348,17 @@ static int unref (lua_State *L) { | |||
| 348 | } | 348 | } |
| 349 | 349 | ||
| 350 | static int newuserdata (lua_State *L) { | 350 | static int newuserdata (lua_State *L) { |
| 351 | if (lua_isnumber(L, 2)) | 351 | if (lua_isnumber(L, 2)) { |
| 352 | lua_pushusertag(L, (void *)luaL_check_int(L, 1), luaL_check_int(L, 2)); | 352 | int tag = luaL_check_int(L, 2); |
| 353 | else | 353 | int res = lua_pushuserdata(L, (void *)luaL_check_int(L, 1)); |
| 354 | if (tag) lua_settag(L, tag); | ||
| 355 | lua_pushnumber(L, res); | ||
| 356 | return 2; | ||
| 357 | } | ||
| 358 | else { | ||
| 354 | lua_newuserdata(L, luaL_check_int(L, 1)); | 359 | lua_newuserdata(L, luaL_check_int(L, 1)); |
| 355 | return 1; | 360 | return 1; |
| 361 | } | ||
| 356 | } | 362 | } |
| 357 | 363 | ||
| 358 | static int udataval (lua_State *L) { | 364 | static int udataval (lua_State *L) { |
| @@ -361,6 +367,10 @@ static int udataval (lua_State *L) { | |||
| 361 | return 1; | 367 | return 1; |
| 362 | } | 368 | } |
| 363 | 369 | ||
| 370 | static int newtag (lua_State *L) { | ||
| 371 | lua_pushnumber(L, lua_newtype(L, lua_tostring(L, 1), lua_tonumber(L, 2))); | ||
| 372 | return 1; | ||
| 373 | } | ||
| 364 | 374 | ||
| 365 | static int doonnewstack (lua_State *L) { | 375 | static int doonnewstack (lua_State *L) { |
| 366 | lua_State *L1 = lua_open(L, luaL_check_int(L, 1)); | 376 | lua_State *L1 = lua_open(L, luaL_check_int(L, 1)); |
| @@ -631,6 +641,7 @@ static const struct luaL_reg tests_funcs[] = { | |||
| 631 | {"unref", unref}, | 641 | {"unref", unref}, |
| 632 | {"newuserdata", newuserdata}, | 642 | {"newuserdata", newuserdata}, |
| 633 | {"udataval", udataval}, | 643 | {"udataval", udataval}, |
| 644 | {"newtag", newtag}, | ||
| 634 | {"doonnewstack", doonnewstack}, | 645 | {"doonnewstack", doonnewstack}, |
| 635 | {"newstate", newstate}, | 646 | {"newstate", newstate}, |
| 636 | {"closestate", closestate}, | 647 | {"closestate", closestate}, |
