diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2014-12-08 13:26:55 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2014-12-08 13:26:55 -0200 |
commit | 594d7266af6c0a899e5218df444178c16327563e (patch) | |
tree | 6317243b58dd2067ffe17df24a7f13c8baf2a8a3 | |
parent | ab4a890d04acf63fa3552af2c7d821b8360e42d4 (diff) | |
download | lua-594d7266af6c0a899e5218df444178c16327563e.tar.gz lua-594d7266af6c0a899e5218df444178c16327563e.tar.bz2 lua-594d7266af6c0a899e5218df444178c16327563e.zip |
'assert' checks that it has (at least) one parameter + 'assert' ensures
it passes only one value to 'error'
-rw-r--r-- | lbaselib.c | 9 |
1 files changed, 5 insertions, 4 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lbaselib.c,v 1.306 2014/11/02 19:19:04 roberto Exp roberto $ | 2 | ** $Id: lbaselib.c,v 1.307 2014/11/10 14:25:52 roberto Exp roberto $ |
3 | ** Basic library | 3 | ** Basic library |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -388,9 +388,10 @@ static int luaB_assert (lua_State *L) { | |||
388 | if (lua_toboolean(L, 1)) /* condition is true? */ | 388 | if (lua_toboolean(L, 1)) /* condition is true? */ |
389 | return lua_gettop(L); /* return all arguments */ | 389 | return lua_gettop(L); /* return all arguments */ |
390 | else { /* error */ | 390 | else { /* error */ |
391 | if (lua_isnone(L, 2)) /* no error message? */ | 391 | luaL_checkany(L, 1); /* there must be a condition */ |
392 | lua_pushliteral(L, "assertion failed!"); /* use standard message */ | 392 | lua_remove(L, 1); /* remove it */ |
393 | lua_remove(L, 1); /* remove the condition (if there is one...) */ | 393 | lua_pushliteral(L, "assertion failed!"); /* default message */ |
394 | lua_settop(L, 1); /* leave only message (default if no other one) */ | ||
394 | return luaB_error(L); /* call 'error' */ | 395 | return luaB_error(L); /* call 'error' */ |
395 | } | 396 | } |
396 | } | 397 | } |