diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2002-12-19 09:11:55 -0200 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2002-12-19 09:11:55 -0200 |
| commit | dd8edecae19251a3b89502416a2e7f8e75b2bd20 (patch) | |
| tree | 10c94c2a2f89f534ca9a5b9b2591008bda8eae17 /ltests.c | |
| parent | 28021c5c663702a1b1890f0e5d280c36be8a6c16 (diff) | |
| download | lua-dd8edecae19251a3b89502416a2e7f8e75b2bd20.tar.gz lua-dd8edecae19251a3b89502416a2e7f8e75b2bd20.tar.bz2 lua-dd8edecae19251a3b89502416a2e7f8e75b2bd20.zip | |
new functions to manipulate upvales (get/setupvalue)
Diffstat (limited to 'ltests.c')
| -rw-r--r-- | ltests.c | 21 |
1 files changed, 20 insertions, 1 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ltests.c,v 1.147 2002/12/04 17:29:05 roberto Exp roberto $ | 2 | ** $Id: ltests.c,v 1.148 2002/12/04 17:38:31 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 | */ |
| @@ -384,6 +384,24 @@ static int metatable (lua_State *L) { | |||
| 384 | return 1; | 384 | return 1; |
| 385 | } | 385 | } |
| 386 | 386 | ||
| 387 | |||
| 388 | static int upvalue (lua_State *L) { | ||
| 389 | int n = luaL_checkint(L, 2); | ||
| 390 | luaL_checktype(L, 1, LUA_TFUNCTION); | ||
| 391 | if (lua_isnone(L, 3)) { | ||
| 392 | const char *name = lua_getupvalue(L, 1, n); | ||
| 393 | if (name == NULL) return 0; | ||
| 394 | lua_pushstring(L, name); | ||
| 395 | return 2; | ||
| 396 | } | ||
| 397 | else { | ||
| 398 | const char *name = lua_setupvalue(L, 1, n); | ||
| 399 | lua_pushstring(L, name); | ||
| 400 | return 1; | ||
| 401 | } | ||
| 402 | } | ||
| 403 | |||
| 404 | |||
| 387 | static int newuserdata (lua_State *L) { | 405 | static int newuserdata (lua_State *L) { |
| 388 | size_t size = luaL_checkint(L, 1); | 406 | size_t size = luaL_checkint(L, 1); |
| 389 | char *p = cast(char *, lua_newuserdata(L, size)); | 407 | char *p = cast(char *, lua_newuserdata(L, size)); |
| @@ -754,6 +772,7 @@ static const struct luaL_reg tests_funcs[] = { | |||
| 754 | {"d2s", d2s}, | 772 | {"d2s", d2s}, |
| 755 | {"s2d", s2d}, | 773 | {"s2d", s2d}, |
| 756 | {"metatable", metatable}, | 774 | {"metatable", metatable}, |
| 775 | {"upvalue", upvalue}, | ||
| 757 | {"newuserdata", newuserdata}, | 776 | {"newuserdata", newuserdata}, |
| 758 | {"pushuserdata", pushuserdata}, | 777 | {"pushuserdata", pushuserdata}, |
| 759 | {"udataval", udataval}, | 778 | {"udataval", udataval}, |
