diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2019-06-04 11:22:21 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2019-06-04 11:22:21 -0300 |
commit | 14edd364c3abcb758e74c68a2bdd4ddaeefdae2a (patch) | |
tree | 9350100ad9b962cae6e6406b4d7462e1443bc137 /lbaselib.c | |
parent | 514d94274853e6f0dfd6bb2ffa2e1fc64db926dd (diff) | |
download | lua-14edd364c3abcb758e74c68a2bdd4ddaeefdae2a.tar.gz lua-14edd364c3abcb758e74c68a2bdd4ddaeefdae2a.tar.bz2 lua-14edd364c3abcb758e74c68a2bdd4ddaeefdae2a.zip |
Function 'warn' is vararg
Instead of a 'tocont' flag, the function 'warn' in Lua now receives all
message pieces as multiple arguments in a single call. Besides being
simpler to use, this implementation ensures that Lua code cannot create
unfinished warnings.
Diffstat (limited to 'lbaselib.c')
-rw-r--r-- | lbaselib.c | 15 |
1 files changed, 13 insertions, 2 deletions
@@ -37,9 +37,20 @@ static int luaB_print (lua_State *L) { | |||
37 | } | 37 | } |
38 | 38 | ||
39 | 39 | ||
40 | /* | ||
41 | ** Creates a warning with all given arguments. | ||
42 | ** Check first for errors; otherwise an error may interrupt | ||
43 | ** the composition of a warning, leaving it unfinished. | ||
44 | */ | ||
40 | static int luaB_warn (lua_State *L) { | 45 | static int luaB_warn (lua_State *L) { |
41 | const char *msg = luaL_checkstring(L, 1); | 46 | int n = lua_gettop(L); /* number of arguments */ |
42 | lua_warning(L, msg, lua_toboolean(L, 2)); | 47 | int i; |
48 | luaL_checkstring(L, 1); /* at least one argument */ | ||
49 | for (i = 2; i <= n; i++) | ||
50 | luaL_checkstring(L, i); /* make sure all arguments are strings */ | ||
51 | for (i = 1; i <= n; i++) /* compose warning */ | ||
52 | lua_warning(L, lua_tostring(L, i), 1); | ||
53 | lua_warning(L, "", 0); /* close warning */ | ||
43 | return 0; | 54 | return 0; |
44 | } | 55 | } |
45 | 56 | ||