Navigation Menu

Skip to content

Commit

Permalink
builtin: Fix print crashing on nil "holes".
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
kaeza authored and est31 committed Feb 8, 2016
1 parent 16c7008 commit 4301953
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion builtin/init.lua
Expand Up @@ -12,7 +12,11 @@ if core.print then
-- Override native print and use
-- terminal if that's turned on
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
core.print = nil -- don't pollute our namespace
end
Expand Down

0 comments on commit 4301953

Please sign in to comment.