diff options
| -rw-r--r-- | lauxlib.c | 6 | ||||
| -rw-r--r-- | lauxlib.h | 4 | ||||
| -rw-r--r-- | lbaselib.c | 6 | ||||
| -rw-r--r-- | ldblib.c | 14 | ||||
| -rw-r--r-- | liolib.c | 10 | ||||
| -rw-r--r-- | lmathlib.c | 4 | ||||
| -rw-r--r-- | loadlib.c | 8 | ||||
| -rw-r--r-- | lstrlib.c | 4 | ||||
| -rw-r--r-- | lutf8lib.c | 4 | ||||
| -rwxr-xr-x | manual/2html | 1 | ||||
| -rw-r--r-- | manual/manual.of | 87 | ||||
| -rw-r--r-- | testes/api.lua | 2 | ||||
| -rw-r--r-- | testes/db.lua | 6 | ||||
| -rw-r--r-- | testes/errors.lua | 10 | ||||
| -rw-r--r-- | testes/files.lua | 30 | ||||
| -rw-r--r-- | testes/literals.lua | 2 | ||||
| -rw-r--r-- | testes/math.lua | 100 | ||||
| -rw-r--r-- | testes/pm.lua | 22 | ||||
| -rw-r--r-- | testes/strings.lua | 6 | ||||
| -rw-r--r-- | testes/utf8.lua | 4 |
20 files changed, 176 insertions, 154 deletions
| @@ -249,7 +249,7 @@ LUALIB_API int luaL_fileresult (lua_State *L, int stat, const char *fname) { | |||
| 249 | return 1; | 249 | return 1; |
| 250 | } | 250 | } |
| 251 | else { | 251 | else { |
| 252 | lua_pushnil(L); | 252 | luaL_pushfail(L); |
| 253 | if (fname) | 253 | if (fname) |
| 254 | lua_pushfstring(L, "%s: %s", fname, strerror(en)); | 254 | lua_pushfstring(L, "%s: %s", fname, strerror(en)); |
| 255 | else | 255 | else |
| @@ -291,10 +291,10 @@ LUALIB_API int luaL_execresult (lua_State *L, int stat) { | |||
| 291 | if (*what == 'e' && stat == 0) /* successful termination? */ | 291 | if (*what == 'e' && stat == 0) /* successful termination? */ |
| 292 | lua_pushboolean(L, 1); | 292 | lua_pushboolean(L, 1); |
| 293 | else | 293 | else |
| 294 | lua_pushnil(L); | 294 | luaL_pushfail(L); |
| 295 | lua_pushstring(L, what); | 295 | lua_pushstring(L, what); |
| 296 | lua_pushinteger(L, stat); | 296 | lua_pushinteger(L, stat); |
| 297 | return 3; /* return true/nil,what,code */ | 297 | return 3; /* return true/fail,what,code */ |
| 298 | } | 298 | } |
| 299 | } | 299 | } |
| 300 | 300 | ||
| @@ -153,6 +153,10 @@ LUALIB_API void (luaL_requiref) (lua_State *L, const char *modname, | |||
| 153 | #define luaL_loadbuffer(L,s,sz,n) luaL_loadbufferx(L,s,sz,n,NULL) | 153 | #define luaL_loadbuffer(L,s,sz,n) luaL_loadbufferx(L,s,sz,n,NULL) |
| 154 | 154 | ||
| 155 | 155 | ||
| 156 | /* push the value used to represent failure/error */ | ||
| 157 | #define luaL_pushfail(L) lua_pushnil(L) | ||
| 158 | |||
| 159 | |||
| 156 | /* | 160 | /* |
| 157 | ** {====================================================== | 161 | ** {====================================================== |
| 158 | ** Generic Buffer manipulation | 162 | ** Generic Buffer manipulation |
| @@ -106,7 +106,7 @@ static int luaB_tonumber (lua_State *L) { | |||
| 106 | return 1; | 106 | return 1; |
| 107 | } /* else not a number */ | 107 | } /* else not a number */ |
| 108 | } /* else not a number */ | 108 | } /* else not a number */ |
| 109 | lua_pushnil(L); /* not a number */ | 109 | luaL_pushfail(L); /* not a number */ |
| 110 | return 1; | 110 | return 1; |
| 111 | } | 111 | } |
| 112 | 112 | ||
| @@ -308,9 +308,9 @@ static int load_aux (lua_State *L, int status, int envidx) { | |||
| 308 | return 1; | 308 | return 1; |
| 309 | } | 309 | } |
| 310 | else { /* error (message is on top of the stack) */ | 310 | else { /* error (message is on top of the stack) */ |
| 311 | lua_pushnil(L); | 311 | luaL_pushfail(L); |
| 312 | lua_insert(L, -2); /* put before error message */ | 312 | lua_insert(L, -2); /* put before error message */ |
| 313 | return 2; /* return nil plus error message */ | 313 | return 2; /* return fail plus error message */ |
| 314 | } | 314 | } |
| 315 | } | 315 | } |
| 316 | 316 | ||
| @@ -65,7 +65,7 @@ static int db_setmetatable (lua_State *L) { | |||
| 65 | static int db_getuservalue (lua_State *L) { | 65 | static int db_getuservalue (lua_State *L) { |
| 66 | int n = (int)luaL_optinteger(L, 2, 1); | 66 | int n = (int)luaL_optinteger(L, 2, 1); |
| 67 | if (lua_type(L, 1) != LUA_TUSERDATA) | 67 | if (lua_type(L, 1) != LUA_TUSERDATA) |
| 68 | lua_pushnil(L); | 68 | luaL_pushfail(L); |
| 69 | else if (lua_getiuservalue(L, 1, n) != LUA_TNONE) { | 69 | else if (lua_getiuservalue(L, 1, n) != LUA_TNONE) { |
| 70 | lua_pushboolean(L, 1); | 70 | lua_pushboolean(L, 1); |
| 71 | return 2; | 71 | return 2; |
| @@ -80,7 +80,7 @@ static int db_setuservalue (lua_State *L) { | |||
| 80 | luaL_checkany(L, 2); | 80 | luaL_checkany(L, 2); |
| 81 | lua_settop(L, 2); | 81 | lua_settop(L, 2); |
| 82 | if (!lua_setiuservalue(L, 1, n)) | 82 | if (!lua_setiuservalue(L, 1, n)) |
| 83 | lua_pushnil(L); | 83 | luaL_pushfail(L); |
| 84 | return 1; | 84 | return 1; |
| 85 | } | 85 | } |
| 86 | 86 | ||
| @@ -159,7 +159,7 @@ static int db_getinfo (lua_State *L) { | |||
| 159 | } | 159 | } |
| 160 | else { /* stack level */ | 160 | else { /* stack level */ |
| 161 | if (!lua_getstack(L1, (int)luaL_checkinteger(L, arg + 1), &ar)) { | 161 | if (!lua_getstack(L1, (int)luaL_checkinteger(L, arg + 1), &ar)) { |
| 162 | lua_pushnil(L); /* level out of range */ | 162 | luaL_pushfail(L); /* level out of range */ |
| 163 | return 1; | 163 | return 1; |
| 164 | } | 164 | } |
| 165 | } | 165 | } |
| @@ -223,7 +223,7 @@ static int db_getlocal (lua_State *L) { | |||
| 223 | return 2; | 223 | return 2; |
| 224 | } | 224 | } |
| 225 | else { | 225 | else { |
| 226 | lua_pushnil(L); /* no name (nor value) */ | 226 | luaL_pushfail(L); /* no name (nor value) */ |
| 227 | return 1; | 227 | return 1; |
| 228 | } | 228 | } |
| 229 | } | 229 | } |
| @@ -389,8 +389,10 @@ static int db_gethook (lua_State *L) { | |||
| 389 | char buff[5]; | 389 | char buff[5]; |
| 390 | int mask = lua_gethookmask(L1); | 390 | int mask = lua_gethookmask(L1); |
| 391 | lua_Hook hook = lua_gethook(L1); | 391 | lua_Hook hook = lua_gethook(L1); |
| 392 | if (hook == NULL) /* no hook? */ | 392 | if (hook == NULL) { /* no hook? */ |
| 393 | lua_pushnil(L); | 393 | luaL_pushfail(L); |
| 394 | return 1; | ||
| 395 | } | ||
| 394 | else if (hook != hookf) /* external hook? */ | 396 | else if (hook != hookf) /* external hook? */ |
| 395 | lua_pushliteral(L, "external hook"); | 397 | lua_pushliteral(L, "external hook"); |
| 396 | else { /* hook table must exist */ | 398 | else { /* hook table must exist */ |
| @@ -153,7 +153,7 @@ static int io_type (lua_State *L) { | |||
| 153 | luaL_checkany(L, 1); | 153 | luaL_checkany(L, 1); |
| 154 | p = (LStream *)luaL_testudata(L, 1, LUA_FILEHANDLE); | 154 | p = (LStream *)luaL_testudata(L, 1, LUA_FILEHANDLE); |
| 155 | if (p == NULL) | 155 | if (p == NULL) |
| 156 | lua_pushnil(L); /* not a file */ | 156 | luaL_pushfail(L); /* not a file */ |
| 157 | else if (isclosed(p)) | 157 | else if (isclosed(p)) |
| 158 | lua_pushliteral(L, "closed file"); | 158 | lua_pushliteral(L, "closed file"); |
| 159 | else | 159 | else |
| @@ -593,7 +593,7 @@ static int g_read (lua_State *L, FILE *f, int first) { | |||
| 593 | return luaL_fileresult(L, 0, NULL); | 593 | return luaL_fileresult(L, 0, NULL); |
| 594 | if (!success) { | 594 | if (!success) { |
| 595 | lua_pop(L, 1); /* remove last result */ | 595 | lua_pop(L, 1); /* remove last result */ |
| 596 | lua_pushnil(L); /* push nil instead */ | 596 | luaL_pushfail(L); /* push nil instead */ |
| 597 | } | 597 | } |
| 598 | return n - first; | 598 | return n - first; |
| 599 | } | 599 | } |
| @@ -624,9 +624,9 @@ static int io_readline (lua_State *L) { | |||
| 624 | lua_pushvalue(L, lua_upvalueindex(3 + i)); | 624 | lua_pushvalue(L, lua_upvalueindex(3 + i)); |
| 625 | n = g_read(L, p->f, 2); /* 'n' is number of results */ | 625 | n = g_read(L, p->f, 2); /* 'n' is number of results */ |
| 626 | lua_assert(n > 0); /* should return at least a nil */ | 626 | lua_assert(n > 0); /* should return at least a nil */ |
| 627 | if (!lua_isnil(L, -n)) /* read at least one value? */ | 627 | if (lua_toboolean(L, -n)) /* read at least one value? */ |
| 628 | return n; /* return them */ | 628 | return n; /* return them */ |
| 629 | else { /* first result is nil: EOF or error */ | 629 | else { /* first result is false: EOF or error */ |
| 630 | if (n > 1) { /* is there error information? */ | 630 | if (n > 1) { /* is there error information? */ |
| 631 | /* 2nd result is error message */ | 631 | /* 2nd result is error message */ |
| 632 | return luaL_error(L, "%s", lua_tostring(L, -n + 1)); | 632 | return luaL_error(L, "%s", lua_tostring(L, -n + 1)); |
| @@ -782,7 +782,7 @@ static void createmeta (lua_State *L) { | |||
| 782 | static int io_noclose (lua_State *L) { | 782 | static int io_noclose (lua_State *L) { |
| 783 | LStream *p = tolstream(L); | 783 | LStream *p = tolstream(L); |
| 784 | p->closef = &io_noclose; /* keep file opened */ | 784 | p->closef = &io_noclose; /* keep file opened */ |
| 785 | lua_pushnil(L); | 785 | luaL_pushfail(L); |
| 786 | lua_pushliteral(L, "cannot close standard file"); | 786 | lua_pushliteral(L, "cannot close standard file"); |
| 787 | return 2; | 787 | return 2; |
| 788 | } | 788 | } |
| @@ -77,7 +77,7 @@ static int math_toint (lua_State *L) { | |||
| 77 | lua_pushinteger(L, n); | 77 | lua_pushinteger(L, n); |
| 78 | else { | 78 | else { |
| 79 | luaL_checkany(L, 1); | 79 | luaL_checkany(L, 1); |
| 80 | lua_pushnil(L); /* value is not convertible to integer */ | 80 | luaL_pushfail(L); /* value is not convertible to integer */ |
| 81 | } | 81 | } |
| 82 | return 1; | 82 | return 1; |
| 83 | } | 83 | } |
| @@ -235,7 +235,7 @@ static int math_type (lua_State *L) { | |||
| 235 | lua_pushstring(L, (lua_isinteger(L, 1)) ? "integer" : "float"); | 235 | lua_pushstring(L, (lua_isinteger(L, 1)) ? "integer" : "float"); |
| 236 | else { | 236 | else { |
| 237 | luaL_checkany(L, 1); | 237 | luaL_checkany(L, 1); |
| 238 | lua_pushnil(L); | 238 | luaL_pushfail(L); |
| 239 | } | 239 | } |
| 240 | return 1; | 240 | return 1; |
| 241 | } | 241 | } |
| @@ -408,10 +408,10 @@ static int ll_loadlib (lua_State *L) { | |||
| 408 | if (stat == 0) /* no errors? */ | 408 | if (stat == 0) /* no errors? */ |
| 409 | return 1; /* return the loaded function */ | 409 | return 1; /* return the loaded function */ |
| 410 | else { /* error; error message is on stack top */ | 410 | else { /* error; error message is on stack top */ |
| 411 | lua_pushnil(L); | 411 | luaL_pushfail(L); |
| 412 | lua_insert(L, -2); | 412 | lua_insert(L, -2); |
| 413 | lua_pushstring(L, (stat == ERRLIB) ? LIB_FAIL : "init"); | 413 | lua_pushstring(L, (stat == ERRLIB) ? LIB_FAIL : "init"); |
| 414 | return 3; /* return nil, error message, and where */ | 414 | return 3; /* return fail, error message, and where */ |
| 415 | } | 415 | } |
| 416 | } | 416 | } |
| 417 | 417 | ||
| @@ -505,9 +505,9 @@ static int ll_searchpath (lua_State *L) { | |||
| 505 | luaL_optstring(L, 4, LUA_DIRSEP)); | 505 | luaL_optstring(L, 4, LUA_DIRSEP)); |
| 506 | if (f != NULL) return 1; | 506 | if (f != NULL) return 1; |
| 507 | else { /* error message is on top of the stack */ | 507 | else { /* error message is on top of the stack */ |
| 508 | lua_pushnil(L); | 508 | luaL_pushfail(L); |
| 509 | lua_insert(L, -2); | 509 | lua_insert(L, -2); |
| 510 | return 2; /* return nil + error message */ | 510 | return 2; /* return fail + error message */ |
| 511 | } | 511 | } |
| 512 | } | 512 | } |
| 513 | 513 | ||
| @@ -744,7 +744,7 @@ static int str_find_aux (lua_State *L, int find) { | |||
| 744 | const char *p = luaL_checklstring(L, 2, &lp); | 744 | const char *p = luaL_checklstring(L, 2, &lp); |
| 745 | size_t init = posrelatI(luaL_optinteger(L, 3, 1), ls) - 1; | 745 | size_t init = posrelatI(luaL_optinteger(L, 3, 1), ls) - 1; |
| 746 | if (init > ls) { /* start after string's end? */ | 746 | if (init > ls) { /* start after string's end? */ |
| 747 | lua_pushnil(L); /* cannot find anything */ | 747 | luaL_pushfail(L); /* cannot find anything */ |
| 748 | return 1; | 748 | return 1; |
| 749 | } | 749 | } |
| 750 | /* explicit request or no special characters? */ | 750 | /* explicit request or no special characters? */ |
| @@ -779,7 +779,7 @@ static int str_find_aux (lua_State *L, int find) { | |||
| 779 | } | 779 | } |
| 780 | } while (s1++ < ms.src_end && !anchor); | 780 | } while (s1++ < ms.src_end && !anchor); |
| 781 | } | 781 | } |
| 782 | lua_pushnil(L); /* not found */ | 782 | luaL_pushfail(L); /* not found */ |
| 783 | return 1; | 783 | return 1; |
| 784 | } | 784 | } |
| 785 | 785 | ||
| @@ -103,7 +103,7 @@ static int utflen (lua_State *L) { | |||
| 103 | while (posi <= posj) { | 103 | while (posi <= posj) { |
| 104 | const char *s1 = utf8_decode(s + posi, NULL, !lax); | 104 | const char *s1 = utf8_decode(s + posi, NULL, !lax); |
| 105 | if (s1 == NULL) { /* conversion error? */ | 105 | if (s1 == NULL) { /* conversion error? */ |
| 106 | lua_pushnil(L); /* return nil ... */ | 106 | luaL_pushfail(L); /* return fail ... */ |
| 107 | lua_pushinteger(L, posi + 1); /* ... and current position */ | 107 | lua_pushinteger(L, posi + 1); /* ... and current position */ |
| 108 | return 2; | 108 | return 2; |
| 109 | } | 109 | } |
| @@ -216,7 +216,7 @@ static int byteoffset (lua_State *L) { | |||
| 216 | if (n == 0) /* did it find given character? */ | 216 | if (n == 0) /* did it find given character? */ |
| 217 | lua_pushinteger(L, posi + 1); | 217 | lua_pushinteger(L, posi + 1); |
| 218 | else /* no such character */ | 218 | else /* no such character */ |
| 219 | lua_pushnil(L); | 219 | luaL_pushfail(L); |
| 220 | return 1; | 220 | return 1; |
| 221 | } | 221 | } |
| 222 | 222 | ||
diff --git a/manual/2html b/manual/2html index 605c6e59..a300f8d4 100755 --- a/manual/2html +++ b/manual/2html | |||
| @@ -324,6 +324,7 @@ N = function (s) return (string.gsub(s, " ", " ")) end, | |||
| 324 | NE = id, -- tag"foreignphrase", | 324 | NE = id, -- tag"foreignphrase", |
| 325 | num = id, | 325 | num = id, |
| 326 | ["nil"] = fixed(Tag.b"nil"), | 326 | ["nil"] = fixed(Tag.b"nil"), |
| 327 | fail = fixed(Tag.b"fail"), | ||
| 327 | Open = fixed"{", | 328 | Open = fixed"{", |
| 328 | part = section("h1", true), | 329 | part = section("h1", true), |
| 329 | Pat = compose(verbfixed, prepos("'", "'")), | 330 | Pat = compose(verbfixed, prepos("'", "'")), |
diff --git a/manual/manual.of b/manual/manual.of index bb6ae884..53073a54 100644 --- a/manual/manual.of +++ b/manual/manual.of | |||
| @@ -4058,12 +4058,15 @@ Returns 0 if the userdata does not have that value. | |||
| 4058 | 4058 | ||
| 4059 | } | 4059 | } |
| 4060 | 4060 | ||
| 4061 | @APIEntry{void lua_setmetatable (lua_State *L, int index);| | 4061 | @APIEntry{int lua_setmetatable (lua_State *L, int index);| |
| 4062 | @apii{1,0,-} | 4062 | @apii{1,0,-} |
| 4063 | 4063 | ||
| 4064 | Pops a table from the stack and | 4064 | Pops a table from the stack and |
| 4065 | sets it as the new metatable for the value at the given index. | 4065 | sets it as the new metatable for the value at the given index. |
| 4066 | 4066 | ||
| 4067 | (For historical reasons, this function returns an @id{int}, | ||
| 4068 | which now is always 1.) | ||
| 4069 | |||
| 4067 | } | 4070 | } |
| 4068 | 4071 | ||
| 4069 | @APIEntry{void lua_settable (lua_State *L, int index);| | 4072 | @APIEntry{void lua_settable (lua_State *L, int index);| |
| @@ -5782,7 +5785,7 @@ that will be called to close the stream | |||
| 5782 | when the handle is closed or collected; | 5785 | when the handle is closed or collected; |
| 5783 | this function receives the file handle as its sole argument and | 5786 | this function receives the file handle as its sole argument and |
| 5784 | must return either @true, in case of success, | 5787 | must return either @true, in case of success, |
| 5785 | or @nil plus an error message, in case of error. | 5788 | or a false value plus an error message, in case of error. |
| 5786 | Once Lua calls this field, | 5789 | Once Lua calls this field, |
| 5787 | it changes the field value to @id{NULL} | 5790 | it changes the field value to @id{NULL} |
| 5788 | to signal that the handle is closed. | 5791 | to signal that the handle is closed. |
| @@ -5904,6 +5907,14 @@ to its expected parameters. | |||
| 5904 | For instance, a function documented as @T{foo(arg)} | 5907 | For instance, a function documented as @T{foo(arg)} |
| 5905 | should not be called without an argument. | 5908 | should not be called without an argument. |
| 5906 | 5909 | ||
| 5910 | The notation @fail means a return value representing | ||
| 5911 | some kind of failure or the absence of a better value to return. | ||
| 5912 | Currently, @fail is equal to @nil, | ||
| 5913 | but that may change in future versions. | ||
| 5914 | The recommendation is to test the success of these functions | ||
| 5915 | with @T{(not status)}, instead of @T{(status == nil)}. | ||
| 5916 | |||
| 5917 | |||
| 5907 | Currently, Lua has the following standard libraries: | 5918 | Currently, Lua has the following standard libraries: |
| 5908 | @itemize{ | 5919 | @itemize{ |
| 5909 | 5920 | ||
| @@ -6108,8 +6119,8 @@ with previous results. | |||
| 6108 | A return of an empty string, @nil, or no value signals the end of the chunk. | 6119 | A return of an empty string, @nil, or no value signals the end of the chunk. |
| 6109 | 6120 | ||
| 6110 | If there are no syntactic errors, | 6121 | If there are no syntactic errors, |
| 6111 | returns the compiled chunk as a function; | 6122 | @id{load} returns the compiled chunk as a function; |
| 6112 | otherwise, returns @nil plus the error message. | 6123 | otherwise, it returns @fail plus the error message. |
| 6113 | 6124 | ||
| 6114 | When you load a main chunk, | 6125 | When you load a main chunk, |
| 6115 | the resulting function will always have exactly one upvalue, | 6126 | the resulting function will always have exactly one upvalue, |
| @@ -6301,7 +6312,7 @@ When called with no @id{base}, | |||
| 6301 | If the argument is already a number or | 6312 | If the argument is already a number or |
| 6302 | a string convertible to a number, | 6313 | a string convertible to a number, |
| 6303 | then @id{tonumber} returns this number; | 6314 | then @id{tonumber} returns this number; |
| 6304 | otherwise, it returns @nil. | 6315 | otherwise, it returns @fail. |
| 6305 | 6316 | ||
| 6306 | The conversion of strings can result in integers or floats, | 6317 | The conversion of strings can result in integers or floats, |
| 6307 | according to the lexical conventions of Lua @see{lexical}. | 6318 | according to the lexical conventions of Lua @see{lexical}. |
| @@ -6315,7 +6326,7 @@ In bases @N{above 10}, the letter @Char{A} (in either upper or lower case) | |||
| 6315 | @N{represents 10}, @Char{B} @N{represents 11}, and so forth, | 6326 | @N{represents 10}, @Char{B} @N{represents 11}, and so forth, |
| 6316 | with @Char{Z} representing 35. | 6327 | with @Char{Z} representing 35. |
| 6317 | If the string @id{e} is not a valid numeral in the given base, | 6328 | If the string @id{e} is not a valid numeral in the given base, |
| 6318 | the function returns @nil. | 6329 | the function returns @fail. |
| 6319 | 6330 | ||
| 6320 | } | 6331 | } |
| 6321 | 6332 | ||
| @@ -6762,7 +6773,7 @@ will try to open the files | |||
| 6762 | 6773 | ||
| 6763 | Returns the resulting name of the first file that it can | 6774 | Returns the resulting name of the first file that it can |
| 6764 | open in read mode (after closing the file), | 6775 | open in read mode (after closing the file), |
| 6765 | or @nil plus an error message if none succeeds. | 6776 | or @fail plus an error message if none succeeds. |
| 6766 | (This error message lists all file names it tried to open.) | 6777 | (This error message lists all file names it tried to open.) |
| 6767 | 6778 | ||
| 6768 | } | 6779 | } |
| @@ -6841,7 +6852,7 @@ Looks for the first match of | |||
| 6841 | @id{pattern} @see{pm} in the string @id{s}. | 6852 | @id{pattern} @see{pm} in the string @id{s}. |
| 6842 | If it finds a match, then @id{find} returns the indices @N{of @T{s}} | 6853 | If it finds a match, then @id{find} returns the indices @N{of @T{s}} |
| 6843 | where this occurrence starts and ends; | 6854 | where this occurrence starts and ends; |
| 6844 | otherwise, it returns @nil. | 6855 | otherwise, it returns @fail. |
| 6845 | A third, optional numeric argument @id{init} specifies | 6856 | A third, optional numeric argument @id{init} specifies |
| 6846 | where to start the search; | 6857 | where to start the search; |
| 6847 | its default value @N{is 1} and can be negative. | 6858 | its default value @N{is 1} and can be negative. |
| @@ -7034,7 +7045,7 @@ Looks for the first @emph{match} of | |||
| 7034 | the @id{pattern} @see{pm} in the string @id{s}. | 7045 | the @id{pattern} @see{pm} in the string @id{s}. |
| 7035 | If it finds one, then @id{match} returns | 7046 | If it finds one, then @id{match} returns |
| 7036 | the captures from the pattern; | 7047 | the captures from the pattern; |
| 7037 | otherwise it returns @nil. | 7048 | otherwise it returns @fail. |
| 7038 | If @id{pattern} specifies no captures, | 7049 | If @id{pattern} specifies no captures, |
| 7039 | then the whole match is returned. | 7050 | then the whole match is returned. |
| 7040 | A third, optional numeric argument @id{init} specifies | 7051 | A third, optional numeric argument @id{init} specifies |
| @@ -7499,7 +7510,7 @@ Returns the number of UTF-8 characters in string @id{s} | |||
| 7499 | that start between positions @id{i} and @id{j} (both inclusive). | 7510 | that start between positions @id{i} and @id{j} (both inclusive). |
| 7500 | The default for @id{i} is @num{1} and for @id{j} is @num{-1}. | 7511 | The default for @id{i} is @num{1} and for @id{j} is @num{-1}. |
| 7501 | If it finds any invalid byte sequence, | 7512 | If it finds any invalid byte sequence, |
| 7502 | returns a false value plus the position of the first invalid byte. | 7513 | returns @fail plus the position of the first invalid byte. |
| 7503 | 7514 | ||
| 7504 | } | 7515 | } |
| 7505 | 7516 | ||
| @@ -7515,7 +7526,7 @@ so that @T{utf8.offset(s, -n)} gets the offset of the | |||
| 7515 | @id{n}-th character from the end of the string. | 7526 | @id{n}-th character from the end of the string. |
| 7516 | If the specified character is neither in the subject | 7527 | If the specified character is neither in the subject |
| 7517 | nor right after its end, | 7528 | nor right after its end, |
| 7518 | the function returns @nil. | 7529 | the function returns @fail. |
| 7519 | 7530 | ||
| 7520 | As a special case, | 7531 | As a special case, |
| 7521 | when @id{n} is 0 the function returns the start of the encoding | 7532 | when @id{n} is 0 the function returns the start of the encoding |
| @@ -7850,7 +7861,7 @@ Returns the tangent of @id{x} (assumed to be in radians). | |||
| 7850 | 7861 | ||
| 7851 | If the value @id{x} is convertible to an integer, | 7862 | If the value @id{x} is convertible to an integer, |
| 7852 | returns that integer. | 7863 | returns that integer. |
| 7853 | Otherwise, returns @nil. | 7864 | Otherwise, returns @fail. |
| 7854 | 7865 | ||
| 7855 | } | 7866 | } |
| 7856 | 7867 | ||
| @@ -7858,7 +7869,7 @@ Otherwise, returns @nil. | |||
| 7858 | 7869 | ||
| 7859 | Returns @St{integer} if @id{x} is an integer, | 7870 | Returns @St{integer} if @id{x} is an integer, |
| 7860 | @St{float} if it is a float, | 7871 | @St{float} if it is a float, |
| 7861 | or @nil if @id{x} is not a number. | 7872 | or @fail if @id{x} is not a number. |
| 7862 | 7873 | ||
| 7863 | } | 7874 | } |
| 7864 | 7875 | ||
| @@ -7897,10 +7908,10 @@ three predefined file handles with their usual meanings from C: | |||
| 7897 | The I/O library never closes these files. | 7908 | The I/O library never closes these files. |
| 7898 | 7909 | ||
| 7899 | Unless otherwise stated, | 7910 | Unless otherwise stated, |
| 7900 | all I/O functions return @nil on failure, | 7911 | all I/O functions return @fail on failure, |
| 7901 | plus an error message as a second result and | 7912 | plus an error message as a second result and |
| 7902 | a system-dependent error code as a third result, | 7913 | a system-dependent error code as a third result, |
| 7903 | and some value different from @nil on success. | 7914 | and some non-false value on success. |
| 7904 | On non-POSIX systems, | 7915 | On non-POSIX systems, |
| 7905 | the computation of the error message and error code | 7916 | the computation of the error message and error code |
| 7906 | in case of errors | 7917 | in case of errors |
| @@ -8021,7 +8032,7 @@ and it is automatically removed when the program ends. | |||
| 8021 | Checks whether @id{obj} is a valid file handle. | 8032 | Checks whether @id{obj} is a valid file handle. |
| 8022 | Returns the string @T{"file"} if @id{obj} is an open file handle, | 8033 | Returns the string @T{"file"} if @id{obj} is an open file handle, |
| 8023 | @T{"closed file"} if @id{obj} is a closed file handle, | 8034 | @T{"closed file"} if @id{obj} is a closed file handle, |
| 8024 | or @nil if @id{obj} is not a file handle. | 8035 | or @fail if @id{obj} is not a file handle. |
| 8025 | 8036 | ||
| 8026 | } | 8037 | } |
| 8027 | 8038 | ||
| @@ -8075,7 +8086,7 @@ Reads the file @id{file}, | |||
| 8075 | according to the given formats, which specify what to read. | 8086 | according to the given formats, which specify what to read. |
| 8076 | For each format, | 8087 | For each format, |
| 8077 | the function returns a string or a number with the characters read, | 8088 | the function returns a string or a number with the characters read, |
| 8078 | or @nil if it cannot read data with the specified format. | 8089 | or @fail if it cannot read data with the specified format. |
| 8079 | (In this latter case, | 8090 | (In this latter case, |
| 8080 | the function does not read subsequent formats.) | 8091 | the function does not read subsequent formats.) |
| 8081 | When called without arguments, | 8092 | When called without arguments, |
| @@ -8094,31 +8105,32 @@ is a valid prefix for a numeral; | |||
| 8094 | if that prefix does not form a valid numeral | 8105 | if that prefix does not form a valid numeral |
| 8095 | (e.g., an empty string, @St{0x}, or @St{3.4e-}) | 8106 | (e.g., an empty string, @St{0x}, or @St{3.4e-}) |
| 8096 | or it is too long (more than 200 characters), | 8107 | or it is too long (more than 200 characters), |
| 8097 | it is discarded and the format returns @nil. | 8108 | it is discarded and the format returns @fail. |
| 8098 | } | 8109 | } |
| 8099 | 8110 | ||
| 8100 | @item{@St{a}| | 8111 | @item{@St{a}| |
| 8101 | reads the whole file, starting at the current position. | 8112 | reads the whole file, starting at the current position. |
| 8102 | On end of file, it returns the empty string. | 8113 | On end of file, it returns the empty string; |
| 8114 | this format never fails. | ||
| 8103 | } | 8115 | } |
| 8104 | 8116 | ||
| 8105 | @item{@St{l}| | 8117 | @item{@St{l}| |
| 8106 | reads the next line skipping the end of line, | 8118 | reads the next line skipping the end of line, |
| 8107 | returning @nil on end of file. | 8119 | returning @fail on end of file. |
| 8108 | This is the default format. | 8120 | This is the default format. |
| 8109 | } | 8121 | } |
| 8110 | 8122 | ||
| 8111 | @item{@St{L}| | 8123 | @item{@St{L}| |
| 8112 | reads the next line keeping the end-of-line character (if present), | 8124 | reads the next line keeping the end-of-line character (if present), |
| 8113 | returning @nil on end of file. | 8125 | returning @fail on end of file. |
| 8114 | } | 8126 | } |
| 8115 | 8127 | ||
| 8116 | @item{@emph{number}| | 8128 | @item{@emph{number}| |
| 8117 | reads a string with up to this number of bytes, | 8129 | reads a string with up to this number of bytes, |
| 8118 | returning @nil on end of file. | 8130 | returning @fail on end of file. |
| 8119 | If @id{number} is zero, | 8131 | If @id{number} is zero, |
| 8120 | it reads nothing and returns an empty string, | 8132 | it reads nothing and returns an empty string, |
| 8121 | or @nil on end of file. | 8133 | or @fail on end of file. |
| 8122 | } | 8134 | } |
| 8123 | 8135 | ||
| 8124 | } | 8136 | } |
| @@ -8139,7 +8151,7 @@ specified by the string @id{whence}, as follows: | |||
| 8139 | } | 8151 | } |
| 8140 | In case of success, @id{seek} returns the final file position, | 8152 | In case of success, @id{seek} returns the final file position, |
| 8141 | measured in bytes from the beginning of the file. | 8153 | measured in bytes from the beginning of the file. |
| 8142 | If @id{seek} fails, it returns @nil, | 8154 | If @id{seek} fails, it returns @fail, |
| 8143 | plus a string describing the error. | 8155 | plus a string describing the error. |
| 8144 | 8156 | ||
| 8145 | The default value for @id{whence} is @T{"cur"}, | 8157 | The default value for @id{whence} is @T{"cur"}, |
| @@ -8179,7 +8191,6 @@ Writes the value of each of its arguments to @id{file}. | |||
| 8179 | The arguments must be strings or numbers. | 8191 | The arguments must be strings or numbers. |
| 8180 | 8192 | ||
| 8181 | In case of success, this function returns @id{file}. | 8193 | In case of success, this function returns @id{file}. |
| 8182 | Otherwise it returns @nil plus a string describing the error. | ||
| 8183 | 8194 | ||
| 8184 | } | 8195 | } |
| 8185 | 8196 | ||
| @@ -8251,7 +8262,7 @@ This function is equivalent to the @ANSI{system}. | |||
| 8251 | It passes @id{command} to be executed by an operating system shell. | 8262 | It passes @id{command} to be executed by an operating system shell. |
| 8252 | Its first result is @true | 8263 | Its first result is @true |
| 8253 | if the command terminated successfully, | 8264 | if the command terminated successfully, |
| 8254 | or @nil otherwise. | 8265 | or @fail otherwise. |
| 8255 | After this first result | 8266 | After this first result |
| 8256 | the function returns a string plus a number, | 8267 | the function returns a string plus a number, |
| 8257 | as follows: | 8268 | as follows: |
| @@ -8293,7 +8304,7 @@ closes the Lua state before exiting. | |||
| 8293 | @LibEntry{os.getenv (varname)| | 8304 | @LibEntry{os.getenv (varname)| |
| 8294 | 8305 | ||
| 8295 | Returns the value of the process environment variable @id{varname}, | 8306 | Returns the value of the process environment variable @id{varname}, |
| 8296 | or @nil if the variable is not defined. | 8307 | or @fail if the variable is not defined. |
| 8297 | 8308 | ||
| 8298 | } | 8309 | } |
| 8299 | 8310 | ||
| @@ -8301,7 +8312,7 @@ or @nil if the variable is not defined. | |||
| 8301 | 8312 | ||
| 8302 | Deletes the file (or empty directory, on @x{POSIX} systems) | 8313 | Deletes the file (or empty directory, on @x{POSIX} systems) |
| 8303 | with the given name. | 8314 | with the given name. |
| 8304 | If this function fails, it returns @nil, | 8315 | If this function fails, it returns @fail |
| 8305 | plus a string describing the error and the error code. | 8316 | plus a string describing the error and the error code. |
| 8306 | Otherwise, it returns true. | 8317 | Otherwise, it returns true. |
| 8307 | 8318 | ||
| @@ -8310,7 +8321,7 @@ Otherwise, it returns true. | |||
| 8310 | @LibEntry{os.rename (oldname, newname)| | 8321 | @LibEntry{os.rename (oldname, newname)| |
| 8311 | 8322 | ||
| 8312 | Renames the file or directory named @id{oldname} to @id{newname}. | 8323 | Renames the file or directory named @id{oldname} to @id{newname}. |
| 8313 | If this function fails, it returns @nil, | 8324 | If this function fails, it returns @fail, |
| 8314 | plus a string describing the error and the error code. | 8325 | plus a string describing the error and the error code. |
| 8315 | Otherwise, it returns true. | 8326 | Otherwise, it returns true. |
| 8316 | 8327 | ||
| @@ -8325,7 +8336,7 @@ Sets the current locale of the program. | |||
| 8325 | @T{"monetary"}, @T{"numeric"}, or @T{"time"}; | 8336 | @T{"monetary"}, @T{"numeric"}, or @T{"time"}; |
| 8326 | the default category is @T{"all"}. | 8337 | the default category is @T{"all"}. |
| 8327 | The function returns the name of the new locale, | 8338 | The function returns the name of the new locale, |
| 8328 | or @nil if the request cannot be honored. | 8339 | or @fail if the request cannot be honored. |
| 8329 | 8340 | ||
| 8330 | If @id{locale} is the empty string, | 8341 | If @id{locale} is the empty string, |
| 8331 | the current locale is set to an implementation-defined native locale. | 8342 | the current locale is set to an implementation-defined native locale. |
| @@ -8444,6 +8455,8 @@ the current hook function, the current hook mask, | |||
| 8444 | and the current hook count, | 8455 | and the current hook count, |
| 8445 | as set by the @Lid{debug.sethook} function. | 8456 | as set by the @Lid{debug.sethook} function. |
| 8446 | 8457 | ||
| 8458 | Returns @fail if there is no active hook. | ||
| 8459 | |||
| 8447 | } | 8460 | } |
| 8448 | 8461 | ||
| 8449 | @LibEntry{debug.getinfo ([thread,] f [, what])| | 8462 | @LibEntry{debug.getinfo ([thread,] f [, what])| |
| @@ -8458,7 +8471,7 @@ of the given thread: | |||
| 8458 | (except for tail calls, which do not count on the stack); | 8471 | (except for tail calls, which do not count on the stack); |
| 8459 | and so on. | 8472 | and so on. |
| 8460 | If @id{f} is a number greater than the number of active functions, | 8473 | If @id{f} is a number greater than the number of active functions, |
| 8461 | then @id{getinfo} returns @nil. | 8474 | then @id{getinfo} returns @fail. |
| 8462 | 8475 | ||
| 8463 | The returned table can contain all the fields returned by @Lid{lua_getinfo}, | 8476 | The returned table can contain all the fields returned by @Lid{lua_getinfo}, |
| 8464 | with the string @id{what} describing which fields to fill in. | 8477 | with the string @id{what} describing which fields to fill in. |
| @@ -8496,7 +8509,8 @@ Compile-time constants may not appear in this listing, | |||
| 8496 | if they were optimized away by the compiler. | 8509 | if they were optimized away by the compiler. |
| 8497 | Negative indices refer to vararg arguments; | 8510 | Negative indices refer to vararg arguments; |
| 8498 | @num{-1} is the first vararg argument. | 8511 | @num{-1} is the first vararg argument. |
| 8499 | The function returns @nil if there is no variable with the given index, | 8512 | The function returns @fail |
| 8513 | if there is no variable with the given index, | ||
| 8500 | and raises an error when called with a level out of range. | 8514 | and raises an error when called with a level out of range. |
| 8501 | (You can call @Lid{debug.getinfo} to check whether the level is valid.) | 8515 | (You can call @Lid{debug.getinfo} to check whether the level is valid.) |
| 8502 | 8516 | ||
| @@ -8527,7 +8541,8 @@ Returns the registry table @see{registry}. | |||
| 8527 | 8541 | ||
| 8528 | This function returns the name and the value of the upvalue | 8542 | This function returns the name and the value of the upvalue |
| 8529 | with index @id{up} of the function @id{f}. | 8543 | with index @id{up} of the function @id{f}. |
| 8530 | The function returns @nil if there is no upvalue with the given index. | 8544 | The function returns @fail |
| 8545 | if there is no upvalue with the given index. | ||
| 8531 | 8546 | ||
| 8532 | (For Lua functions, | 8547 | (For Lua functions, |
| 8533 | upvalues are the external local variables that the function uses, | 8548 | upvalues are the external local variables that the function uses, |
| @@ -8615,7 +8630,7 @@ and @N{level 1} is the hook function.) | |||
| 8615 | 8630 | ||
| 8616 | This function assigns the value @id{value} to the local variable | 8631 | This function assigns the value @id{value} to the local variable |
| 8617 | with index @id{local} of the function at level @id{level} of the stack. | 8632 | with index @id{local} of the function at level @id{level} of the stack. |
| 8618 | The function returns @nil if there is no local | 8633 | The function returns @fail if there is no local |
| 8619 | variable with the given index, | 8634 | variable with the given index, |
| 8620 | and raises an error when called with a @id{level} out of range. | 8635 | and raises an error when called with a @id{level} out of range. |
| 8621 | (You can call @id{getinfo} to check whether the level is valid.) | 8636 | (You can call @id{getinfo} to check whether the level is valid.) |
| @@ -8638,7 +8653,7 @@ Returns @id{value}. | |||
| 8638 | 8653 | ||
| 8639 | This function assigns the value @id{value} to the upvalue | 8654 | This function assigns the value @id{value} to the upvalue |
| 8640 | with index @id{up} of the function @id{f}. | 8655 | with index @id{up} of the function @id{f}. |
| 8641 | The function returns @nil if there is no upvalue | 8656 | The function returns @fail if there is no upvalue |
| 8642 | with the given index. | 8657 | with the given index. |
| 8643 | Otherwise, it returns the name of the upvalue. | 8658 | Otherwise, it returns the name of the upvalue. |
| 8644 | 8659 | ||
| @@ -8653,7 +8668,7 @@ the @id{n}-th user value associated to the given @id{udata}. | |||
| 8653 | @id{udata} must be a full userdata. | 8668 | @id{udata} must be a full userdata. |
| 8654 | 8669 | ||
| 8655 | Returns @id{udata}, | 8670 | Returns @id{udata}, |
| 8656 | or @nil if the userdata does not have that value. | 8671 | or @fail if the userdata does not have that value. |
| 8657 | 8672 | ||
| 8658 | } | 8673 | } |
| 8659 | 8674 | ||
diff --git a/testes/api.lua b/testes/api.lua index 4f9d6717..b2680633 100644 --- a/testes/api.lua +++ b/testes/api.lua | |||
| @@ -698,7 +698,7 @@ for k, v in ipairs(t) do | |||
| 698 | assert(v1 == v and p) | 698 | assert(v1 == v and p) |
| 699 | end | 699 | end |
| 700 | 700 | ||
| 701 | assert(debug.getuservalue(4) == nil) | 701 | assert(not debug.getuservalue(4)) |
| 702 | 702 | ||
| 703 | debug.setuservalue(b, function () return 10 end, 10) | 703 | debug.setuservalue(b, function () return 10 end, 10) |
| 704 | collectgarbage() -- function should not be collected | 704 | collectgarbage() -- function should not be collected |
diff --git a/testes/db.lua b/testes/db.lua index a64a1130..c43243a6 100644 --- a/testes/db.lua +++ b/testes/db.lua | |||
| @@ -351,12 +351,12 @@ assert(g(0,0) == 30) | |||
| 351 | 351 | ||
| 352 | 352 | ||
| 353 | debug.sethook(nil); | 353 | debug.sethook(nil); |
| 354 | assert(debug.gethook() == nil) | 354 | assert(not debug.gethook()) |
| 355 | 355 | ||
| 356 | 356 | ||
| 357 | -- minimal tests for setuservalue/getuservalue | 357 | -- minimal tests for setuservalue/getuservalue |
| 358 | do | 358 | do |
| 359 | assert(debug.setuservalue(io.stdin, 10) == nil) | 359 | assert(not debug.setuservalue(io.stdin, 10)) |
| 360 | local a, b = debug.getuservalue(io.stdin, 10) | 360 | local a, b = debug.getuservalue(io.stdin, 10) |
| 361 | assert(a == nil and not b) | 361 | assert(a == nil and not b) |
| 362 | end | 362 | end |
| @@ -414,7 +414,7 @@ end, "c") | |||
| 414 | a:f(1,2,3,4,5) | 414 | a:f(1,2,3,4,5) |
| 415 | assert(X.self == a and X.a == 1 and X.b == 2 and X.c == nil) | 415 | assert(X.self == a and X.a == 1 and X.b == 2 and X.c == nil) |
| 416 | assert(XX == 12) | 416 | assert(XX == 12) |
| 417 | assert(debug.gethook() == nil) | 417 | assert(not debug.gethook()) |
| 418 | 418 | ||
| 419 | 419 | ||
| 420 | -- testing access to local variables in return hook (bug in 5.2) | 420 | -- testing access to local variables in return hook (bug in 5.2) |
diff --git a/testes/errors.lua b/testes/errors.lua index 6e7b8004..f9623b1d 100644 --- a/testes/errors.lua +++ b/testes/errors.lua | |||
| @@ -18,7 +18,7 @@ end | |||
| 18 | 18 | ||
| 19 | local function doit (s) | 19 | local function doit (s) |
| 20 | local f, msg = load(s) | 20 | local f, msg = load(s) |
| 21 | if f == nil then return msg end | 21 | if not f then return msg end |
| 22 | local cond, msg = pcall(f) | 22 | local cond, msg = pcall(f) |
| 23 | return (not cond) and msg | 23 | return (not cond) and msg |
| 24 | end | 24 | end |
| @@ -312,8 +312,8 @@ end | |||
| 312 | 312 | ||
| 313 | local function lineerror (s, l) | 313 | local function lineerror (s, l) |
| 314 | local err,msg = pcall(load(s)) | 314 | local err,msg = pcall(load(s)) |
| 315 | local line = string.match(msg, ":(%d+):") | 315 | local line = tonumber(string.match(msg, ":(%d+):")) |
| 316 | assert(tonumber(line) == l) | 316 | assert(line == l or (not line and not l)) |
| 317 | end | 317 | end |
| 318 | 318 | ||
| 319 | lineerror("local a\n for i=1,'a' do \n print(i) \n end", 2) | 319 | lineerror("local a\n for i=1,'a' do \n print(i) \n end", 2) |
| @@ -359,7 +359,7 @@ local p = [[ | |||
| 359 | g() | 359 | g() |
| 360 | ]] | 360 | ]] |
| 361 | X=3;lineerror((p), 3) | 361 | X=3;lineerror((p), 3) |
| 362 | X=0;lineerror((p), nil) | 362 | X=0;lineerror((p), false) |
| 363 | X=1;lineerror((p), 2) | 363 | X=1;lineerror((p), 2) |
| 364 | X=2;lineerror((p), 1) | 364 | X=2;lineerror((p), 1) |
| 365 | 365 | ||
| @@ -510,7 +510,7 @@ checksyntax("a\1a = 1", "", "<\\1>", 1) | |||
| 510 | checksyntax("\255a = 1", "", "<\\255>", 1) | 510 | checksyntax("\255a = 1", "", "<\\255>", 1) |
| 511 | 511 | ||
| 512 | doit('I = load("a=9+"); a=3') | 512 | doit('I = load("a=9+"); a=3') |
| 513 | assert(a==3 and I == nil) | 513 | assert(a==3 and not I) |
| 514 | print('+') | 514 | print('+') |
| 515 | 515 | ||
| 516 | lim = 1000 | 516 | lim = 1000 |
diff --git a/testes/files.lua b/testes/files.lua index 585e5948..677c0dc2 100644 --- a/testes/files.lua +++ b/testes/files.lua | |||
| @@ -184,7 +184,7 @@ three | |||
| 184 | local f <close> = assert(io.open(file, "r")) | 184 | local f <close> = assert(io.open(file, "r")) |
| 185 | -- second item failing | 185 | -- second item failing |
| 186 | l1, n1, n2, dummy = f:read("l", "n", "n", "l") | 186 | l1, n1, n2, dummy = f:read("l", "n", "n", "l") |
| 187 | assert(l1 == "a line" and n1 == nil) | 187 | assert(l1 == "a line" and not n1) |
| 188 | end | 188 | end |
| 189 | assert(os.remove(file)) | 189 | assert(os.remove(file)) |
| 190 | 190 | ||
| @@ -228,7 +228,7 @@ assert(f:read("n") == 0Xdeadbeefdeadbeef); assert(f:read(2) == "x\n") | |||
| 228 | assert(f:read("n") == 0x1.13aP3); assert(f:read(1) == "e") | 228 | assert(f:read("n") == 0x1.13aP3); assert(f:read(1) == "e") |
| 229 | 229 | ||
| 230 | do -- attempt to read too long number | 230 | do -- attempt to read too long number |
| 231 | assert(f:read("n") == nil) -- fails | 231 | assert(not f:read("n")) -- fails |
| 232 | local s = f:read("L") -- read rest of line | 232 | local s = f:read("L") -- read rest of line |
| 233 | assert(string.find(s, "^00*\n$")) -- lots of 0's left | 233 | assert(string.find(s, "^00*\n$")) -- lots of 0's left |
| 234 | end | 234 | end |
| @@ -314,13 +314,13 @@ assert(io.read() == "fourth_line") | |||
| 314 | assert(io.read() == "") -- empty line | 314 | assert(io.read() == "") -- empty line |
| 315 | assert(io.read('n') == 3450) | 315 | assert(io.read('n') == 3450) |
| 316 | assert(io.read(1) == '\n') | 316 | assert(io.read(1) == '\n') |
| 317 | assert(io.read(0) == nil) -- end of file | 317 | assert(not io.read(0)) -- end of file |
| 318 | assert(io.read(1) == nil) -- end of file | 318 | assert(not io.read(1)) -- end of file |
| 319 | assert(io.read(30000) == nil) -- end of file | 319 | assert(not io.read(30000)) -- end of file |
| 320 | assert(({io.read(1)})[2] == undef) | 320 | assert(({io.read(1)})[2] == undef) |
| 321 | assert(io.read() == nil) -- end of file | 321 | assert(not io.read()) -- end of file |
| 322 | assert(({io.read()})[2] == undef) | 322 | assert(({io.read()})[2] == undef) |
| 323 | assert(io.read('n') == nil) -- end of file | 323 | assert(not io.read('n')) -- end of file |
| 324 | assert(({io.read('n')})[2] == undef) | 324 | assert(({io.read('n')})[2] == undef) |
| 325 | assert(io.read('a') == '') -- end of file (OK for 'a') | 325 | assert(io.read('a') == '') -- end of file (OK for 'a') |
| 326 | assert(io.read('a') == '') -- end of file (OK for 'a') | 326 | assert(io.read('a') == '') -- end of file (OK for 'a') |
| @@ -356,7 +356,7 @@ assert(io.read(string.len(t)) == t) | |||
| 356 | assert(io.read(1) == ' ') | 356 | assert(io.read(1) == ' ') |
| 357 | assert(io.read(0)) | 357 | assert(io.read(0)) |
| 358 | assert(io.read('a') == ';end of file\n') | 358 | assert(io.read('a') == ';end of file\n') |
| 359 | assert(io.read(0) == nil) | 359 | assert(not io.read(0)) |
| 360 | assert(io.close(io.input())) | 360 | assert(io.close(io.input())) |
| 361 | 361 | ||
| 362 | 362 | ||
| @@ -364,7 +364,7 @@ assert(io.close(io.input())) | |||
| 364 | do | 364 | do |
| 365 | local function ismsg (m) | 365 | local function ismsg (m) |
| 366 | -- error message is not a code number | 366 | -- error message is not a code number |
| 367 | return (type(m) == "string" and tonumber(m) == nil) | 367 | return (type(m) == "string" and not tonumber(m)) |
| 368 | end | 368 | end |
| 369 | 369 | ||
| 370 | -- read | 370 | -- read |
| @@ -393,7 +393,7 @@ assert(io.read"L" == "\n") | |||
| 393 | assert(io.read"L" == "\n") | 393 | assert(io.read"L" == "\n") |
| 394 | assert(io.read"L" == "line\n") | 394 | assert(io.read"L" == "line\n") |
| 395 | assert(io.read"L" == "other") | 395 | assert(io.read"L" == "other") |
| 396 | assert(io.read"L" == nil) | 396 | assert(not io.read"L") |
| 397 | io.input():close() | 397 | io.input():close() |
| 398 | 398 | ||
| 399 | local f = assert(io.open(file)) | 399 | local f = assert(io.open(file)) |
| @@ -462,7 +462,7 @@ end | |||
| 462 | -- test for multipe arguments in 'lines' | 462 | -- test for multipe arguments in 'lines' |
| 463 | io.output(file); io.write"0123456789\n":close() | 463 | io.output(file); io.write"0123456789\n":close() |
| 464 | for a,b in io.lines(file, 1, 1) do | 464 | for a,b in io.lines(file, 1, 1) do |
| 465 | if a == "\n" then assert(b == nil) | 465 | if a == "\n" then assert(not b) |
| 466 | else assert(tonumber(a) == tonumber(b) - 1) | 466 | else assert(tonumber(a) == tonumber(b) - 1) |
| 467 | end | 467 | end |
| 468 | end | 468 | end |
| @@ -473,13 +473,13 @@ end | |||
| 473 | 473 | ||
| 474 | for a,b,c in io.lines(file, "a", 0, 1) do | 474 | for a,b,c in io.lines(file, "a", 0, 1) do |
| 475 | if a == "" then break end | 475 | if a == "" then break end |
| 476 | assert(a == "0123456789\n" and b == nil and c == nil) | 476 | assert(a == "0123456789\n" and not b and not c) |
| 477 | end | 477 | end |
| 478 | collectgarbage() -- to close file in previous iteration | 478 | collectgarbage() -- to close file in previous iteration |
| 479 | 479 | ||
| 480 | io.output(file); io.write"00\n10\n20\n30\n40\n":close() | 480 | io.output(file); io.write"00\n10\n20\n30\n40\n":close() |
| 481 | for a, b in io.lines(file, "n", "n") do | 481 | for a, b in io.lines(file, "n", "n") do |
| 482 | if a == 40 then assert(b == nil) | 482 | if a == 40 then assert(not b) |
| 483 | else assert(a == b - 10) | 483 | else assert(a == b - 10) |
| 484 | end | 484 | end |
| 485 | end | 485 | end |
| @@ -654,7 +654,7 @@ and the rest of the file | |||
| 654 | io.input(file) | 654 | io.input(file) |
| 655 | local _,a,b,c,d,e,h,__ = io.read(1, 'n', 'n', 'l', 'l', 'l', 'a', 10) | 655 | local _,a,b,c,d,e,h,__ = io.read(1, 'n', 'n', 'l', 'l', 'l', 'a', 10) |
| 656 | assert(io.close(io.input())) | 656 | assert(io.close(io.input())) |
| 657 | assert(_ == ' ' and __ == nil) | 657 | assert(_ == ' ' and not __) |
| 658 | assert(type(a) == 'number' and a==123.4 and b==-56e-2) | 658 | assert(type(a) == 'number' and a==123.4 and b==-56e-2) |
| 659 | assert(d=='second line' and e=='third line') | 659 | assert(d=='second line' and e=='third line') |
| 660 | assert(h==[[ | 660 | assert(h==[[ |
| @@ -706,7 +706,7 @@ if not _soft then | |||
| 706 | io.input():seek('set', 0) | 706 | io.input():seek('set', 0) |
| 707 | y = io.read() -- huge line | 707 | y = io.read() -- huge line |
| 708 | assert(x == y..'\n'..io.read()) | 708 | assert(x == y..'\n'..io.read()) |
| 709 | assert(io.read() == nil) | 709 | assert(not io.read()) |
| 710 | io.close(io.input()) | 710 | io.close(io.input()) |
| 711 | assert(os.remove(file)) | 711 | assert(os.remove(file)) |
| 712 | x = nil; y = nil | 712 | x = nil; y = nil |
diff --git a/testes/literals.lua b/testes/literals.lua index 27f9377d..e101eabf 100644 --- a/testes/literals.lua +++ b/testes/literals.lua | |||
| @@ -281,7 +281,7 @@ if os.setlocale("pt_BR") or os.setlocale("ptb") then | |||
| 281 | 281 | ||
| 282 | assert(" 0x.1 " + " 0x,1" + "-0X.1\t" == 0x0.1) | 282 | assert(" 0x.1 " + " 0x,1" + "-0X.1\t" == 0x0.1) |
| 283 | 283 | ||
| 284 | assert(tonumber"inf" == nil and tonumber"NAN" == nil) | 284 | assert(not tonumber"inf" and not tonumber"NAN") |
| 285 | 285 | ||
| 286 | assert(assert(load(string.format("return %q", 4.51)))() == 4.51) | 286 | assert(assert(load(string.format("return %q", 4.51)))() == 4.51) |
| 287 | 287 | ||
diff --git a/testes/math.lua b/testes/math.lua index bad43901..c7dc8285 100644 --- a/testes/math.lua +++ b/testes/math.lua | |||
| @@ -39,7 +39,7 @@ do | |||
| 39 | end | 39 | end |
| 40 | 40 | ||
| 41 | assert(math.type(0) == "integer" and math.type(0.0) == "float" | 41 | assert(math.type(0) == "integer" and math.type(0.0) == "float" |
| 42 | and math.type("10") == nil) | 42 | and not math.type("10")) |
| 43 | 43 | ||
| 44 | 44 | ||
| 45 | local function checkerror (msg, f, ...) | 45 | local function checkerror (msg, f, ...) |
| @@ -381,17 +381,17 @@ assert(tonumber(1/0) == 1/0) | |||
| 381 | 381 | ||
| 382 | -- 'tonumber' with strings | 382 | -- 'tonumber' with strings |
| 383 | assert(tonumber("0") == 0) | 383 | assert(tonumber("0") == 0) |
| 384 | assert(tonumber("") == nil) | 384 | assert(not tonumber("")) |
| 385 | assert(tonumber(" ") == nil) | 385 | assert(not tonumber(" ")) |
| 386 | assert(tonumber("-") == nil) | 386 | assert(not tonumber("-")) |
| 387 | assert(tonumber(" -0x ") == nil) | 387 | assert(not tonumber(" -0x ")) |
| 388 | assert(tonumber{} == nil) | 388 | assert(not tonumber{}) |
| 389 | assert(tonumber'+0.01' == 1/100 and tonumber'+.01' == 0.01 and | 389 | assert(tonumber'+0.01' == 1/100 and tonumber'+.01' == 0.01 and |
| 390 | tonumber'.01' == 0.01 and tonumber'-1.' == -1 and | 390 | tonumber'.01' == 0.01 and tonumber'-1.' == -1 and |
| 391 | tonumber'+1.' == 1) | 391 | tonumber'+1.' == 1) |
| 392 | assert(tonumber'+ 0.01' == nil and tonumber'+.e1' == nil and | 392 | assert(not tonumber'+ 0.01' and not tonumber'+.e1' and |
| 393 | tonumber'1e' == nil and tonumber'1.0e+' == nil and | 393 | not tonumber'1e' and not tonumber'1.0e+' and |
| 394 | tonumber'.' == nil) | 394 | not tonumber'.') |
| 395 | assert(tonumber('-012') == -010-2) | 395 | assert(tonumber('-012') == -010-2) |
| 396 | assert(tonumber('-1.2e2') == - - -120) | 396 | assert(tonumber('-1.2e2') == - - -120) |
| 397 | 397 | ||
| @@ -445,45 +445,45 @@ local function f (...) | |||
| 445 | end | 445 | end |
| 446 | end | 446 | end |
| 447 | 447 | ||
| 448 | assert(f(tonumber('fFfa', 15)) == nil) | 448 | assert(not f(tonumber('fFfa', 15))) |
| 449 | assert(f(tonumber('099', 8)) == nil) | 449 | assert(not f(tonumber('099', 8))) |
| 450 | assert(f(tonumber('1\0', 2)) == nil) | 450 | assert(not f(tonumber('1\0', 2))) |
| 451 | assert(f(tonumber('', 8)) == nil) | 451 | assert(not f(tonumber('', 8))) |
| 452 | assert(f(tonumber(' ', 9)) == nil) | 452 | assert(not f(tonumber(' ', 9))) |
| 453 | assert(f(tonumber(' ', 9)) == nil) | 453 | assert(not f(tonumber(' ', 9))) |
| 454 | assert(f(tonumber('0xf', 10)) == nil) | 454 | assert(not f(tonumber('0xf', 10))) |
| 455 | 455 | ||
| 456 | assert(f(tonumber('inf')) == nil) | 456 | assert(not f(tonumber('inf'))) |
| 457 | assert(f(tonumber(' INF ')) == nil) | 457 | assert(not f(tonumber(' INF '))) |
| 458 | assert(f(tonumber('Nan')) == nil) | 458 | assert(not f(tonumber('Nan'))) |
| 459 | assert(f(tonumber('nan')) == nil) | 459 | assert(not f(tonumber('nan'))) |
| 460 | 460 | ||
| 461 | assert(f(tonumber(' ')) == nil) | 461 | assert(not f(tonumber(' '))) |
| 462 | assert(f(tonumber('')) == nil) | 462 | assert(not f(tonumber(''))) |
| 463 | assert(f(tonumber('1 a')) == nil) | 463 | assert(not f(tonumber('1 a'))) |
| 464 | assert(f(tonumber('1 a', 2)) == nil) | 464 | assert(not f(tonumber('1 a', 2))) |
| 465 | assert(f(tonumber('1\0')) == nil) | 465 | assert(not f(tonumber('1\0'))) |
| 466 | assert(f(tonumber('1 \0')) == nil) | 466 | assert(not f(tonumber('1 \0'))) |
| 467 | assert(f(tonumber('1\0 ')) == nil) | 467 | assert(not f(tonumber('1\0 '))) |
| 468 | assert(f(tonumber('e1')) == nil) | 468 | assert(not f(tonumber('e1'))) |
| 469 | assert(f(tonumber('e 1')) == nil) | 469 | assert(not f(tonumber('e 1'))) |
| 470 | assert(f(tonumber(' 3.4.5 ')) == nil) | 470 | assert(not f(tonumber(' 3.4.5 '))) |
| 471 | 471 | ||
| 472 | 472 | ||
| 473 | -- testing 'tonumber' for invalid hexadecimal formats | 473 | -- testing 'tonumber' for invalid hexadecimal formats |
| 474 | 474 | ||
| 475 | assert(tonumber('0x') == nil) | 475 | assert(not tonumber('0x')) |
| 476 | assert(tonumber('x') == nil) | 476 | assert(not tonumber('x')) |
| 477 | assert(tonumber('x3') == nil) | 477 | assert(not tonumber('x3')) |
| 478 | assert(tonumber('0x3.3.3') == nil) -- two decimal points | 478 | assert(not tonumber('0x3.3.3')) -- two decimal points |
| 479 | assert(tonumber('00x2') == nil) | 479 | assert(not tonumber('00x2')) |
| 480 | assert(tonumber('0x 2') == nil) | 480 | assert(not tonumber('0x 2')) |
| 481 | assert(tonumber('0 x2') == nil) | 481 | assert(not tonumber('0 x2')) |
| 482 | assert(tonumber('23x') == nil) | 482 | assert(not tonumber('23x')) |
| 483 | assert(tonumber('- 0xaa') == nil) | 483 | assert(not tonumber('- 0xaa')) |
| 484 | assert(tonumber('-0xaaP ') == nil) -- no exponent | 484 | assert(not tonumber('-0xaaP ')) -- no exponent |
| 485 | assert(tonumber('0x0.51p') == nil) | 485 | assert(not tonumber('0x0.51p')) |
| 486 | assert(tonumber('0x5p+-2') == nil) | 486 | assert(not tonumber('0x5p+-2')) |
| 487 | 487 | ||
| 488 | 488 | ||
| 489 | -- testing hexadecimal numerals | 489 | -- testing hexadecimal numerals |
| @@ -705,19 +705,19 @@ do -- testing floor & ceil | |||
| 705 | assert(eqT(math.tointeger(maxint), maxint)) | 705 | assert(eqT(math.tointeger(maxint), maxint)) |
| 706 | assert(eqT(math.tointeger(maxint .. ""), maxint)) | 706 | assert(eqT(math.tointeger(maxint .. ""), maxint)) |
| 707 | assert(eqT(math.tointeger(minint + 0.0), minint)) | 707 | assert(eqT(math.tointeger(minint + 0.0), minint)) |
| 708 | assert(math.tointeger(0.0 - minint) == nil) | 708 | assert(not math.tointeger(0.0 - minint)) |
| 709 | assert(math.tointeger(math.pi) == nil) | 709 | assert(not math.tointeger(math.pi)) |
| 710 | assert(math.tointeger(-math.pi) == nil) | 710 | assert(not math.tointeger(-math.pi)) |
| 711 | assert(math.floor(math.huge) == math.huge) | 711 | assert(math.floor(math.huge) == math.huge) |
| 712 | assert(math.ceil(math.huge) == math.huge) | 712 | assert(math.ceil(math.huge) == math.huge) |
| 713 | assert(math.tointeger(math.huge) == nil) | 713 | assert(not math.tointeger(math.huge)) |
| 714 | assert(math.floor(-math.huge) == -math.huge) | 714 | assert(math.floor(-math.huge) == -math.huge) |
| 715 | assert(math.ceil(-math.huge) == -math.huge) | 715 | assert(math.ceil(-math.huge) == -math.huge) |
| 716 | assert(math.tointeger(-math.huge) == nil) | 716 | assert(not math.tointeger(-math.huge)) |
| 717 | assert(math.tointeger("34.0") == 34) | 717 | assert(math.tointeger("34.0") == 34) |
| 718 | assert(math.tointeger("34.3") == nil) | 718 | assert(not math.tointeger("34.3")) |
| 719 | assert(math.tointeger({}) == nil) | 719 | assert(not math.tointeger({})) |
| 720 | assert(math.tointeger(0/0) == nil) -- NaN | 720 | assert(not math.tointeger(0/0)) -- NaN |
| 721 | end | 721 | end |
| 722 | 722 | ||
| 723 | 723 | ||
diff --git a/testes/pm.lua b/testes/pm.lua index 4d87fad2..94bb63ca 100644 --- a/testes/pm.lua +++ b/testes/pm.lua | |||
| @@ -28,10 +28,10 @@ a,b = string.find('a\0a\0a\0a\0\0ab', '\0ab', 2); -- finds at the end | |||
| 28 | assert(a == 9 and b == 11); | 28 | assert(a == 9 and b == 11); |
| 29 | a,b = string.find('a\0a\0a\0a\0\0ab', 'b') -- last position | 29 | a,b = string.find('a\0a\0a\0a\0\0ab', 'b') -- last position |
| 30 | assert(a == 11 and b == 11) | 30 | assert(a == 11 and b == 11) |
| 31 | assert(string.find('a\0a\0a\0a\0\0ab', 'b\0') == nil) -- check ending | 31 | assert(not string.find('a\0a\0a\0a\0\0ab', 'b\0')) -- check ending |
| 32 | assert(string.find('', '\0') == nil) | 32 | assert(not string.find('', '\0')) |
| 33 | assert(string.find('alo123alo', '12') == 4) | 33 | assert(string.find('alo123alo', '12') == 4) |
| 34 | assert(string.find('alo123alo', '^12') == nil) | 34 | assert(not string.find('alo123alo', '^12')) |
| 35 | 35 | ||
| 36 | assert(string.match("aaab", ".*b") == "aaab") | 36 | assert(string.match("aaab", ".*b") == "aaab") |
| 37 | assert(string.match("aaa", ".*a") == "aaa") | 37 | assert(string.match("aaa", ".*a") == "aaa") |
| @@ -57,17 +57,17 @@ assert(f('aaa', 'ab*a') == 'aa') | |||
| 57 | assert(f('aba', 'ab*a') == 'aba') | 57 | assert(f('aba', 'ab*a') == 'aba') |
| 58 | assert(f('aaab', 'a+') == 'aaa') | 58 | assert(f('aaab', 'a+') == 'aaa') |
| 59 | assert(f('aaa', '^.+$') == 'aaa') | 59 | assert(f('aaa', '^.+$') == 'aaa') |
| 60 | assert(f('aaa', 'b+') == nil) | 60 | assert(not f('aaa', 'b+')) |
| 61 | assert(f('aaa', 'ab+a') == nil) | 61 | assert(not f('aaa', 'ab+a')) |
| 62 | assert(f('aba', 'ab+a') == 'aba') | 62 | assert(f('aba', 'ab+a') == 'aba') |
| 63 | assert(f('a$a', '.$') == 'a') | 63 | assert(f('a$a', '.$') == 'a') |
| 64 | assert(f('a$a', '.%$') == 'a$') | 64 | assert(f('a$a', '.%$') == 'a$') |
| 65 | assert(f('a$a', '.$.') == 'a$a') | 65 | assert(f('a$a', '.$.') == 'a$a') |
| 66 | assert(f('a$a', '$$') == nil) | 66 | assert(not f('a$a', '$$')) |
| 67 | assert(f('a$b', 'a$') == nil) | 67 | assert(not f('a$b', 'a$')) |
| 68 | assert(f('a$a', '$') == '') | 68 | assert(f('a$a', '$') == '') |
| 69 | assert(f('', 'b*') == '') | 69 | assert(f('', 'b*') == '') |
| 70 | assert(f('aaa', 'bb*') == nil) | 70 | assert(not f('aaa', 'bb*')) |
| 71 | assert(f('aaab', 'a-') == '') | 71 | assert(f('aaab', 'a-') == '') |
| 72 | assert(f('aaa', '^.-$') == 'aaa') | 72 | assert(f('aaa', '^.-$') == 'aaa') |
| 73 | assert(f('aabaaabaaabaaaba', 'b.*b') == 'baaabaaabaaab') | 73 | assert(f('aabaaabaaabaaaba', 'b.*b') == 'baaabaaabaaab') |
| @@ -101,7 +101,7 @@ end | |||
| 101 | assert(f1('alo alx 123 b\0o b\0o', '(..*) %1') == "b\0o b\0o") | 101 | assert(f1('alo alx 123 b\0o b\0o', '(..*) %1') == "b\0o b\0o") |
| 102 | assert(f1('axz123= 4= 4 34', '(.+)=(.*)=%2 %1') == '3= 4= 4 3') | 102 | assert(f1('axz123= 4= 4 34', '(.+)=(.*)=%2 %1') == '3= 4= 4 3') |
| 103 | assert(f1('=======', '^(=*)=%1$') == '=======') | 103 | assert(f1('=======', '^(=*)=%1$') == '=======') |
| 104 | assert(string.match('==========', '^([=]*)=%1$') == nil) | 104 | assert(not string.match('==========', '^([=]*)=%1$')) |
| 105 | 105 | ||
| 106 | local function range (i, j) | 106 | local function range (i, j) |
| 107 | if i <= j then | 107 | if i <= j then |
| @@ -135,7 +135,7 @@ print('+'); | |||
| 135 | assert(string.match("alo xyzK", "(%w+)K") == "xyz") | 135 | assert(string.match("alo xyzK", "(%w+)K") == "xyz") |
| 136 | assert(string.match("254 K", "(%d*)K") == "") | 136 | assert(string.match("254 K", "(%d*)K") == "") |
| 137 | assert(string.match("alo ", "(%w*)$") == "") | 137 | assert(string.match("alo ", "(%w*)$") == "") |
| 138 | assert(string.match("alo ", "(%w+)$") == nil) | 138 | assert(not string.match("alo ", "(%w+)$")) |
| 139 | assert(string.find("(álo)", "%(á") == 1) | 139 | assert(string.find("(álo)", "%(á") == 1) |
| 140 | local a, b, c, d, e = string.match("âlo alo", "^(((.).).* (%w*))$") | 140 | local a, b, c, d, e = string.match("âlo alo", "^(((.).).* (%w*))$") |
| 141 | assert(a == 'âlo alo' and b == 'âl' and c == 'â' and d == 'alo' and e == nil) | 141 | assert(a == 'âlo alo' and b == 'âl' and c == 'â' and d == 'alo' and e == nil) |
| @@ -209,7 +209,7 @@ assert(s == r and t[1] == 1 and t[3] == 3 and t[7] == 4 and t[13] == 4) | |||
| 209 | 209 | ||
| 210 | 210 | ||
| 211 | function isbalanced (s) | 211 | function isbalanced (s) |
| 212 | return string.find(string.gsub(s, "%b()", ""), "[()]") == nil | 212 | return not string.find(string.gsub(s, "%b()", ""), "[()]") |
| 213 | end | 213 | end |
| 214 | 214 | ||
| 215 | assert(isbalanced("(9 ((8))(\0) 7) \0\0 a b ()(c)() a")) | 215 | assert(isbalanced("(9 ((8))(\0) 7) \0\0 a b ()(c)() a")) |
diff --git a/testes/strings.lua b/testes/strings.lua index 2e0e160f..97875ec0 100644 --- a/testes/strings.lua +++ b/testes/strings.lua | |||
| @@ -56,13 +56,13 @@ a,b = string.find("123456789", "345") | |||
| 56 | assert(string.sub("123456789", a, b) == "345") | 56 | assert(string.sub("123456789", a, b) == "345") |
| 57 | assert(string.find("1234567890123456789", "345", 3) == 3) | 57 | assert(string.find("1234567890123456789", "345", 3) == 3) |
| 58 | assert(string.find("1234567890123456789", "345", 4) == 13) | 58 | assert(string.find("1234567890123456789", "345", 4) == 13) |
| 59 | assert(string.find("1234567890123456789", "346", 4) == nil) | 59 | assert(not string.find("1234567890123456789", "346", 4)) |
| 60 | assert(string.find("1234567890123456789", ".45", -9) == 13) | 60 | assert(string.find("1234567890123456789", ".45", -9) == 13) |
| 61 | assert(string.find("abcdefg", "\0", 5, 1) == nil) | 61 | assert(not string.find("abcdefg", "\0", 5, 1)) |
| 62 | assert(string.find("", "") == 1) | 62 | assert(string.find("", "") == 1) |
| 63 | assert(string.find("", "", 1) == 1) | 63 | assert(string.find("", "", 1) == 1) |
| 64 | assert(not string.find("", "", 2)) | 64 | assert(not string.find("", "", 2)) |
| 65 | assert(string.find('', 'aaa', 1) == nil) | 65 | assert(not string.find('', 'aaa', 1)) |
| 66 | assert(('alo(.)alo'):find('(.)', 1, 1) == 4) | 66 | assert(('alo(.)alo'):find('(.)', 1, 1) == 4) |
| 67 | 67 | ||
| 68 | assert(string.len("") == 0) | 68 | assert(string.len("") == 0) |
diff --git a/testes/utf8.lua b/testes/utf8.lua index acbb181d..5954f6e8 100644 --- a/testes/utf8.lua +++ b/testes/utf8.lua | |||
| @@ -30,8 +30,8 @@ local function checksyntax (s, t) | |||
| 30 | assert(assert(load(ts))() == s) | 30 | assert(assert(load(ts))() == s) |
| 31 | end | 31 | end |
| 32 | 32 | ||
| 33 | assert(utf8.offset("alo", 5) == nil) | 33 | assert(not utf8.offset("alo", 5)) |
| 34 | assert(utf8.offset("alo", -4) == nil) | 34 | assert(not utf8.offset("alo", -4)) |
| 35 | 35 | ||
| 36 | -- 'check' makes several tests over the validity of string 's'. | 36 | -- 'check' makes several tests over the validity of string 's'. |
| 37 | -- 't' is the list of codepoints of 's'. | 37 | -- 't' is the list of codepoints of 's'. |
