diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2001-02-13 14:52:01 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2001-02-13 14:52:01 -0200 |
commit | 1c2501fad4de5a06407500587751d71f7331a872 (patch) | |
tree | 56a3af73b4e37744aab3f0ad6a9b7278aebaad57 | |
parent | a4ae1475e354ff61eda8fe64745de42526a4c53e (diff) | |
download | lua-1c2501fad4de5a06407500587751d71f7331a872.tar.gz lua-1c2501fad4de5a06407500587751d71f7331a872.tar.bz2 lua-1c2501fad4de5a06407500587751d71f7331a872.zip |
tests for string alignment
-rw-r--r-- | ltests.c | 32 |
1 files changed, 23 insertions, 9 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ltests.c,v 1.66 2001/02/09 20:22:29 roberto Exp roberto $ | 2 | ** $Id: ltests.c,v 1.67 2001/02/09 20:29:33 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 | */ |
@@ -224,6 +224,13 @@ static int listlocals (lua_State *L) { | |||
224 | /* }====================================================== */ | 224 | /* }====================================================== */ |
225 | 225 | ||
226 | 226 | ||
227 | static int pushbool (lua_State *L, int b) { | ||
228 | if (b) lua_pushnumber(L, 1); | ||
229 | else lua_pushnil(L); | ||
230 | return 1; | ||
231 | } | ||
232 | |||
233 | |||
227 | 234 | ||
228 | static int get_limits (lua_State *L) { | 235 | static int get_limits (lua_State *L) { |
229 | lua_newtable(L); | 236 | lua_newtable(L); |
@@ -352,7 +359,7 @@ static int newuserdata (lua_State *L) { | |||
352 | int tag = luaL_check_int(L, 2); | 359 | int tag = luaL_check_int(L, 2); |
353 | int res = lua_pushuserdata(L, (void *)luaL_check_int(L, 1)); | 360 | int res = lua_pushuserdata(L, (void *)luaL_check_int(L, 1)); |
354 | if (tag) lua_settag(L, tag); | 361 | if (tag) lua_settag(L, tag); |
355 | lua_pushnumber(L, res); | 362 | pushbool(L, res); |
356 | return 2; | 363 | return 2; |
357 | } | 364 | } |
358 | else { | 365 | else { |
@@ -385,6 +392,18 @@ static int doonnewstack (lua_State *L) { | |||
385 | } | 392 | } |
386 | 393 | ||
387 | 394 | ||
395 | static int s2d (lua_State *L) { | ||
396 | lua_pushnumber(L, *(double *)luaL_check_string(L, 1)); | ||
397 | return 1; | ||
398 | } | ||
399 | |||
400 | static int d2s (lua_State *L) { | ||
401 | double d = luaL_check_number(L, 1); | ||
402 | lua_pushlstring(L, (char *)&d, sizeof(d)); | ||
403 | return 1; | ||
404 | } | ||
405 | |||
406 | |||
388 | static int newstate (lua_State *L) { | 407 | static int newstate (lua_State *L) { |
389 | lua_State *L1 = lua_open(NULL, luaL_check_int(L, 1)); | 408 | lua_State *L1 = lua_open(NULL, luaL_check_int(L, 1)); |
390 | if (L1) { | 409 | if (L1) { |
@@ -446,12 +465,6 @@ static int settagmethod (lua_State *L) { | |||
446 | return 1; | 465 | return 1; |
447 | } | 466 | } |
448 | 467 | ||
449 | static int pushbool (lua_State *L, int b) { | ||
450 | if (b) lua_pushnumber(L, 1); | ||
451 | else lua_pushnil(L); | ||
452 | return 1; | ||
453 | } | ||
454 | |||
455 | static int equal (lua_State *L) { | 468 | static int equal (lua_State *L) { |
456 | return pushbool(L, lua_equal(L, 1, 2)); | 469 | return pushbool(L, lua_equal(L, 1, 2)); |
457 | } | 470 | } |
@@ -540,7 +553,6 @@ static int testC (lua_State *L) { | |||
540 | } | 553 | } |
541 | else if EQ("tostring") { | 554 | else if EQ("tostring") { |
542 | const char *s = lua_tostring(L, getnum); | 555 | const char *s = lua_tostring(L, getnum); |
543 | lua_assert((unsigned long)s % 4 == 0); /* check alignment */ | ||
544 | lua_pushstring(L, s); | 556 | lua_pushstring(L, s); |
545 | } | 557 | } |
546 | else if EQ("tonumber") { | 558 | else if EQ("tonumber") { |
@@ -643,6 +655,8 @@ static const struct luaL_reg tests_funcs[] = { | |||
643 | {"ref", tref}, | 655 | {"ref", tref}, |
644 | {"getref", getref}, | 656 | {"getref", getref}, |
645 | {"unref", unref}, | 657 | {"unref", unref}, |
658 | {"d2s", d2s}, | ||
659 | {"s2d", s2d}, | ||
646 | {"newuserdata", newuserdata}, | 660 | {"newuserdata", newuserdata}, |
647 | {"udataval", udataval}, | 661 | {"udataval", udataval}, |
648 | {"newtag", newtag}, | 662 | {"newtag", newtag}, |