diff options
Diffstat (limited to '')
-rw-r--r-- | ltests.c | 109 |
1 files changed, 68 insertions, 41 deletions
@@ -327,37 +327,40 @@ void lua_printobj (lua_State *L, struct GCObject *o) { | |||
327 | 327 | ||
328 | 328 | ||
329 | void lua_printvalue (TValue *v) { | 329 | void lua_printvalue (TValue *v) { |
330 | switch (ttype(v)) { | 330 | switch (ttypetag(v)) { |
331 | case LUA_TNUMBER: { | 331 | case LUA_VNUMINT: case LUA_VNUMFLT: { |
332 | char buff[LUA_N2SBUFFSZ]; | 332 | char buff[LUA_N2SBUFFSZ]; |
333 | unsigned len = luaO_tostringbuff(v, buff); | 333 | unsigned len = luaO_tostringbuff(v, buff); |
334 | buff[len] = '\0'; | 334 | buff[len] = '\0'; |
335 | printf("%s", buff); | 335 | printf("%s", buff); |
336 | break; | 336 | break; |
337 | } | 337 | } |
338 | case LUA_TSTRING: { | 338 | case LUA_VSHRSTR: |
339 | printf("'%s'", getstr(tsvalue(v))); | 339 | printf("'%s'", getstr(tsvalue(v))); break; |
340 | break; | 340 | case LUA_VLNGSTR: |
341 | } | 341 | printf("'%.30s...'", getstr(tsvalue(v))); break; |
342 | case LUA_TBOOLEAN: { | 342 | case LUA_VFALSE: |
343 | printf("%s", (!l_isfalse(v) ? "true" : "false")); | 343 | printf("%s", "false"); break; |
344 | break; | 344 | case LUA_VTRUE: |
345 | } | 345 | printf("%s", "true"); break; |
346 | case LUA_TLIGHTUSERDATA: { | 346 | case LUA_VLIGHTUSERDATA: |
347 | printf("light udata: %p", pvalue(v)); | 347 | printf("light udata: %p", pvalue(v)); break; |
348 | break; | 348 | case LUA_VUSERDATA: |
349 | } | 349 | printf("full udata: %p", uvalue(v)); break; |
350 | case LUA_TNIL: { | 350 | case LUA_VNIL: |
351 | printf("nil"); | 351 | printf("nil"); break; |
352 | break; | 352 | case LUA_VLCF: |
353 | } | 353 | printf("light C function: %p", fvalue(v)); break; |
354 | default: { | 354 | case LUA_VCCL: |
355 | if (ttislcf(v)) | 355 | printf("C closure: %p", clCvalue(v)); break; |
356 | printf("light C function: %p", fvalue(v)); | 356 | case LUA_VLCL: |
357 | else /* must be collectable */ | 357 | printf("Lua function: %p", clLvalue(v)); break; |
358 | printf("%s: %p", ttypename(ttype(v)), gcvalue(v)); | 358 | case LUA_VTHREAD: |
359 | break; | 359 | printf("thread: %p", thvalue(v)); break; |
360 | } | 360 | case LUA_VTABLE: |
361 | printf("table: %p", hvalue(v)); break; | ||
362 | default: | ||
363 | lua_assert(0); | ||
361 | } | 364 | } |
362 | } | 365 | } |
363 | 366 | ||
@@ -907,9 +910,9 @@ static int get_limits (lua_State *L) { | |||
907 | 910 | ||
908 | static int mem_query (lua_State *L) { | 911 | static int mem_query (lua_State *L) { |
909 | if (lua_isnone(L, 1)) { | 912 | if (lua_isnone(L, 1)) { |
910 | lua_pushinteger(L, cast(lua_Integer, l_memcontrol.total)); | 913 | lua_pushinteger(L, cast_Integer(l_memcontrol.total)); |
911 | lua_pushinteger(L, cast(lua_Integer, l_memcontrol.numblocks)); | 914 | lua_pushinteger(L, cast_Integer(l_memcontrol.numblocks)); |
912 | lua_pushinteger(L, cast(lua_Integer, l_memcontrol.maxmem)); | 915 | lua_pushinteger(L, cast_Integer(l_memcontrol.maxmem)); |
913 | return 3; | 916 | return 3; |
914 | } | 917 | } |
915 | else if (lua_isnumber(L, 1)) { | 918 | else if (lua_isnumber(L, 1)) { |
@@ -923,7 +926,7 @@ static int mem_query (lua_State *L) { | |||
923 | int i; | 926 | int i; |
924 | for (i = LUA_NUMTYPES - 1; i >= 0; i--) { | 927 | for (i = LUA_NUMTYPES - 1; i >= 0; i--) { |
925 | if (strcmp(t, ttypename(i)) == 0) { | 928 | if (strcmp(t, ttypename(i)) == 0) { |
926 | lua_pushinteger(L, cast(lua_Integer, l_memcontrol.objcount[i])); | 929 | lua_pushinteger(L, cast_Integer(l_memcontrol.objcount[i])); |
927 | return 1; | 930 | return 1; |
928 | } | 931 | } |
929 | } | 932 | } |
@@ -1063,15 +1066,19 @@ static int tracegc (lua_State *L) { | |||
1063 | 1066 | ||
1064 | static int hash_query (lua_State *L) { | 1067 | static int hash_query (lua_State *L) { |
1065 | if (lua_isnone(L, 2)) { | 1068 | if (lua_isnone(L, 2)) { |
1069 | TString *ts; | ||
1066 | luaL_argcheck(L, lua_type(L, 1) == LUA_TSTRING, 1, "string expected"); | 1070 | luaL_argcheck(L, lua_type(L, 1) == LUA_TSTRING, 1, "string expected"); |
1067 | lua_pushinteger(L, cast_int(tsvalue(obj_at(L, 1))->hash)); | 1071 | ts = tsvalue(obj_at(L, 1)); |
1072 | if (ts->tt == LUA_VLNGSTR) | ||
1073 | luaS_hashlongstr(ts); /* make sure long string has a hash */ | ||
1074 | lua_pushinteger(L, cast_int(ts->hash)); | ||
1068 | } | 1075 | } |
1069 | else { | 1076 | else { |
1070 | TValue *o = obj_at(L, 1); | 1077 | TValue *o = obj_at(L, 1); |
1071 | Table *t; | 1078 | Table *t; |
1072 | luaL_checktype(L, 2, LUA_TTABLE); | 1079 | luaL_checktype(L, 2, LUA_TTABLE); |
1073 | t = hvalue(obj_at(L, 2)); | 1080 | t = hvalue(obj_at(L, 2)); |
1074 | lua_pushinteger(L, cast(lua_Integer, luaH_mainposition(t, o) - t->node)); | 1081 | lua_pushinteger(L, cast_Integer(luaH_mainposition(t, o) - t->node)); |
1075 | } | 1082 | } |
1076 | return 1; | 1083 | return 1; |
1077 | } | 1084 | } |
@@ -1079,9 +1086,9 @@ static int hash_query (lua_State *L) { | |||
1079 | 1086 | ||
1080 | static int stacklevel (lua_State *L) { | 1087 | static int stacklevel (lua_State *L) { |
1081 | int a = 0; | 1088 | int a = 0; |
1082 | lua_pushinteger(L, cast(lua_Integer, L->top.p - L->stack.p)); | 1089 | lua_pushinteger(L, cast_Integer(L->top.p - L->stack.p)); |
1083 | lua_pushinteger(L, stacksize(L)); | 1090 | lua_pushinteger(L, stacksize(L)); |
1084 | lua_pushinteger(L, cast(lua_Integer, L->nCcalls)); | 1091 | lua_pushinteger(L, cast_Integer(L->nCcalls)); |
1085 | lua_pushinteger(L, L->nci); | 1092 | lua_pushinteger(L, L->nci); |
1086 | lua_pushinteger(L, (lua_Integer)(size_t)&a); | 1093 | lua_pushinteger(L, (lua_Integer)(size_t)&a); |
1087 | return 5; | 1094 | return 5; |
@@ -1096,9 +1103,9 @@ static int table_query (lua_State *L) { | |||
1096 | t = hvalue(obj_at(L, 1)); | 1103 | t = hvalue(obj_at(L, 1)); |
1097 | asize = t->asize; | 1104 | asize = t->asize; |
1098 | if (i == -1) { | 1105 | if (i == -1) { |
1099 | lua_pushinteger(L, cast(lua_Integer, asize)); | 1106 | lua_pushinteger(L, cast_Integer(asize)); |
1100 | lua_pushinteger(L, cast(lua_Integer, allocsizenode(t))); | 1107 | lua_pushinteger(L, cast_Integer(allocsizenode(t))); |
1101 | lua_pushinteger(L, cast(lua_Integer, asize > 0 ? *lenhint(t) : 0)); | 1108 | lua_pushinteger(L, cast_Integer(asize > 0 ? *lenhint(t) : 0)); |
1102 | return 3; | 1109 | return 3; |
1103 | } | 1110 | } |
1104 | else if (cast_uint(i) < asize) { | 1111 | else if (cast_uint(i) < asize) { |
@@ -1154,7 +1161,7 @@ static int test_codeparam (lua_State *L) { | |||
1154 | static int test_applyparam (lua_State *L) { | 1161 | static int test_applyparam (lua_State *L) { |
1155 | lua_Integer p = luaL_checkinteger(L, 1); | 1162 | lua_Integer p = luaL_checkinteger(L, 1); |
1156 | lua_Integer x = luaL_checkinteger(L, 2); | 1163 | lua_Integer x = luaL_checkinteger(L, 2); |
1157 | lua_pushinteger(L, cast(lua_Integer, luaO_applyparam(cast_byte(p), x))); | 1164 | lua_pushinteger(L, cast_Integer(luaO_applyparam(cast_byte(p), x))); |
1158 | return 1; | 1165 | return 1; |
1159 | } | 1166 | } |
1160 | 1167 | ||
@@ -1254,7 +1261,7 @@ static int pushuserdata (lua_State *L) { | |||
1254 | 1261 | ||
1255 | 1262 | ||
1256 | static int udataval (lua_State *L) { | 1263 | static int udataval (lua_State *L) { |
1257 | lua_pushinteger(L, cast(lua_Integer, cast(size_t, lua_touserdata(L, 1)))); | 1264 | lua_pushinteger(L, cast_st2S(cast_sizet(lua_touserdata(L, 1)))); |
1258 | return 1; | 1265 | return 1; |
1259 | } | 1266 | } |
1260 | 1267 | ||
@@ -1291,7 +1298,7 @@ static int num2int (lua_State *L) { | |||
1291 | 1298 | ||
1292 | 1299 | ||
1293 | static int makeseed (lua_State *L) { | 1300 | static int makeseed (lua_State *L) { |
1294 | lua_pushinteger(L, cast(lua_Integer, luaL_makeseed(L))); | 1301 | lua_pushinteger(L, cast_Integer(luaL_makeseed(L))); |
1295 | return 1; | 1302 | return 1; |
1296 | } | 1303 | } |
1297 | 1304 | ||
@@ -1635,7 +1642,7 @@ static int runC (lua_State *L, lua_State *L1, const char *pc) { | |||
1635 | } | 1642 | } |
1636 | else if EQ("func2num") { | 1643 | else if EQ("func2num") { |
1637 | lua_CFunction func = lua_tocfunction(L1, getindex); | 1644 | lua_CFunction func = lua_tocfunction(L1, getindex); |
1638 | lua_pushinteger(L1, cast(lua_Integer, cast(size_t, func))); | 1645 | lua_pushinteger(L1, cast_st2S(cast_sizet(func))); |
1639 | } | 1646 | } |
1640 | else if EQ("getfield") { | 1647 | else if EQ("getfield") { |
1641 | int t = getindex; | 1648 | int t = getindex; |
@@ -2008,7 +2015,7 @@ static int Cfunc (lua_State *L) { | |||
2008 | static int Cfunck (lua_State *L, int status, lua_KContext ctx) { | 2015 | static int Cfunck (lua_State *L, int status, lua_KContext ctx) { |
2009 | lua_pushstring(L, statcodes[status]); | 2016 | lua_pushstring(L, statcodes[status]); |
2010 | lua_setglobal(L, "status"); | 2017 | lua_setglobal(L, "status"); |
2011 | lua_pushinteger(L, cast(lua_Integer, ctx)); | 2018 | lua_pushinteger(L, cast_Integer(ctx)); |
2012 | lua_setglobal(L, "ctx"); | 2019 | lua_setglobal(L, "ctx"); |
2013 | return runC(L, L, lua_tostring(L, cast_int(ctx))); | 2020 | return runC(L, L, lua_tostring(L, cast_int(ctx))); |
2014 | } | 2021 | } |
@@ -2103,6 +2110,25 @@ static int coresume (lua_State *L) { | |||
2103 | } | 2110 | } |
2104 | } | 2111 | } |
2105 | 2112 | ||
2113 | #if !defined(LUA_USE_POSIX) | ||
2114 | |||
2115 | #define nonblock NULL | ||
2116 | |||
2117 | #else | ||
2118 | |||
2119 | #include <unistd.h> | ||
2120 | #include <fcntl.h> | ||
2121 | |||
2122 | static int nonblock (lua_State *L) { | ||
2123 | FILE *f = cast(luaL_Stream*, luaL_checkudata(L, 1, LUA_FILEHANDLE))->f; | ||
2124 | int fd = fileno(f); | ||
2125 | int flags = fcntl(fd, F_GETFL, 0); | ||
2126 | flags |= O_NONBLOCK; | ||
2127 | fcntl(fd, F_SETFL, flags); | ||
2128 | return 0; | ||
2129 | } | ||
2130 | #endif | ||
2131 | |||
2106 | /* }====================================================== */ | 2132 | /* }====================================================== */ |
2107 | 2133 | ||
2108 | 2134 | ||
@@ -2156,6 +2182,7 @@ static const struct luaL_Reg tests_funcs[] = { | |||
2156 | {"upvalue", upvalue}, | 2182 | {"upvalue", upvalue}, |
2157 | {"externKstr", externKstr}, | 2183 | {"externKstr", externKstr}, |
2158 | {"externstr", externstr}, | 2184 | {"externstr", externstr}, |
2185 | {"nonblock", nonblock}, | ||
2159 | {NULL, NULL} | 2186 | {NULL, NULL} |
2160 | }; | 2187 | }; |
2161 | 2188 | ||