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.
This commit is contained in:
Roberto Ierusalimschy
2019-06-04 11:22:21 -03:00
parent 514d942748
commit 14edd364c3
4 changed files with 43 additions and 20 deletions

View File

@@ -347,10 +347,26 @@ NoRun("syntax error", "lua -e a")
NoRun("'-l' needs argument", "lua -l")
if T then -- auxiliary library?
if T then -- test library?
print("testing 'not enough memory' to create a state")
NoRun("not enough memory", "env MEMLIMIT=100 lua")
-- testing 'warn'
warn("@123", "456", "789")
assert(_WARN == "@123456789")
end
do
-- 'warn' must get at least one argument
local st, msg = pcall(warn)
assert(string.find(msg, "string expected"))
-- 'warn' does not leave unfinished warning in case of errors
-- (message would appear in next warning)
st, msg = pcall(warn, "SHOULD NOT APPEAR", {})
assert(string.find(msg, "string expected"))
end
print('+')
print('testing Ctrl C')