aboutsummaryrefslogtreecommitdiff
path: root/ltests.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2001-06-06 15:00:19 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2001-06-06 15:00:19 -0300
commitd5b83ead90fba27faa344c72406d85987d2460a4 (patch)
tree96d73c1b872b6b01a28c0586b871d37185034ba9 /ltests.c
parentda673d31aaa05e8dff60c0b601b9f15c4f9182a8 (diff)
downloadlua-d5b83ead90fba27faa344c72406d85987d2460a4.tar.gz
lua-d5b83ead90fba27faa344c72406d85987d2460a4.tar.bz2
lua-d5b83ead90fba27faa344c72406d85987d2460a4.zip
new implementation for userdatas, without `keys'
Diffstat (limited to 'ltests.c')
-rw-r--r--ltests.c38
1 files changed, 21 insertions, 17 deletions
diff --git a/ltests.c b/ltests.c
index 95d7813d..b666a917 100644
--- a/ltests.c
+++ b/ltests.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ltests.c,v 1.80 2001/04/23 16:35:45 roberto Exp roberto $ 2** $Id: ltests.c,v 1.81 2001/06/05 18:17:01 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*/
@@ -290,7 +290,7 @@ static int mem_query (lua_State *L) {
290static int hash_query (lua_State *L) { 290static int hash_query (lua_State *L) {
291 if (lua_isnull(L, 2)) { 291 if (lua_isnull(L, 2)) {
292 luaL_arg_check(L, lua_tag(L, 1) == LUA_TSTRING, 1, l_s("string expected")); 292 luaL_arg_check(L, lua_tag(L, 1) == LUA_TSTRING, 1, l_s("string expected"));
293 lua_pushnumber(L, tsvalue(luaA_index(L, 1))->u.s.hash); 293 lua_pushnumber(L, tsvalue(luaA_index(L, 1))->hash);
294 } 294 }
295 else { 295 else {
296 Hash *t; 296 Hash *t;
@@ -339,8 +339,7 @@ static int table_query (lua_State *L) {
339 339
340 340
341static int string_query (lua_State *L) { 341static int string_query (lua_State *L) {
342 stringtable *tb = (*luaL_check_string(L, 1) == l_c('s')) ? &G(L)->strt : 342 stringtable *tb = &G(L)->strt;
343 &G(L)->udt;
344 int s = luaL_opt_int(L, 2, 0) - 1; 343 int s = luaL_opt_int(L, 2, 0) - 1;
345 if (s==-1) { 344 if (s==-1) {
346 lua_pushnumber(L ,tb->nuse); 345 lua_pushnumber(L ,tb->nuse);
@@ -390,19 +389,22 @@ static int unref (lua_State *L) {
390} 389}
391 390
392static int newuserdata (lua_State *L) { 391static int newuserdata (lua_State *L) {
393 if (lua_isnumber(L, 2)) { 392 size_t size = luaL_check_int(L, 1);
394 int tag = luaL_check_int(L, 2); 393 l_char *p = (l_char *)lua_newuserdata(L, size);
395 int res = lua_pushuserdata(L, (void *)luaL_check_int(L, 1)); 394 while (size--) *p++ = l_c('\0');
396 if (tag) lua_settag(L, tag); 395 return 1;
397 pushbool(L, res); 396}
398 return 2; 397
399 } 398static int newuserdatabox (lua_State *L) {
400 else { 399 lua_newuserdatabox(L, (void *)luaL_check_int(L, 1));
401 size_t size = luaL_check_int(L, 1); 400 return 1;
402 l_char *p = (l_char *)lua_newuserdata(L, size); 401}
403 while (size--) *p++ = l_c('\0'); 402
404 return 1; 403static int settag (lua_State *L) {
405 } 404 luaL_checkany(L, 1);
405 lua_pushvalue(L, 1); /* push value */
406 lua_settag(L, luaL_check_int(L, 2));
407 return 1; /* return value */
406} 408}
407 409
408static int udataval (lua_State *L) { 410static int udataval (lua_State *L) {
@@ -691,6 +693,8 @@ static const struct luaL_reg tests_funcs[] = {
691 {l_s("d2s"), d2s}, 693 {l_s("d2s"), d2s},
692 {l_s("s2d"), s2d}, 694 {l_s("s2d"), s2d},
693 {l_s("newuserdata"), newuserdata}, 695 {l_s("newuserdata"), newuserdata},
696 {l_s("newuserdatabox"), newuserdatabox},
697 {l_s("settag"), settag},
694 {l_s("udataval"), udataval}, 698 {l_s("udataval"), udataval},
695 {l_s("newtag"), newtag}, 699 {l_s("newtag"), newtag},
696 {l_s("doonnewstack"), doonnewstack}, 700 {l_s("doonnewstack"), doonnewstack},