Skip to content
Snippets Groups Projects
Commit 43019538 authored by Diego Martínez's avatar Diego Martínez Committed by est31
Browse files

builtin: Fix `print` crashing on nil "holes".

The engine implementation of `print` packs the varargs into a
table and passes the table directly to `table.concat`. If you
pass any value not supported by `table.concat` (particularly
`nil`), the server crashes. This is unexpected behavior, as
`print` is supposed to be able to work with anything.

This patch changes the implementation so it first converts
all arguments using `tostring`, which fixes the issue and
makes the custom `print` function compatible with the stock
Lua behavior.
parent 16c70087
No related branches found
No related tags found
No related merge requests found
...@@ -12,7 +12,11 @@ if core.print then ...@@ -12,7 +12,11 @@ if core.print then
-- Override native print and use -- Override native print and use
-- terminal if that's turned on -- terminal if that's turned on
function print(...) function print(...)
core_print(table.concat({...}, "\t")) local n, t = select("#", ...), { ... }
for i = 1, n do
t[i] = tostring(t[i])
end
core_print(table.concat(t, "\t"))
end end
core.print = nil -- don't pollute our namespace core.print = nil -- don't pollute our namespace
end end
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment