__tostring recursion crash on windows

  • From: Simon Schick <demwizzy@xxxxxxxxx>
  • To: luajit@xxxxxxxxxxxxx
  • Date: Tue, 25 Mar 2014 10:29:28 +0100

Recently I found someone posting the following snippet on a forum and was
wondering why it would crash:

tabletest = {}
setmetatable(tabletest,
{
__index = function(...) print("index", ...) end,
__newindex = function(...) print("newindex", ...) end,
__add = function(...) print("add", ...) end,
__mul = function(...) print("mul", ...) end,
__sub = function(...) print("sub", ...) end,
__div = function(...) print("div", ...) end,
__unm = function(...) print("unm", ...) end,
__pow = function(...) print("pow", ...) end,
__concat = function(...) print("concat", ...) end,
__eq = function(...) print("eq", ...) end,
__lt = function(...) print("lt", ...) end,
__le = function(...) print("le", ...) end,
__tostring = function(...) print("tostring", ...) end,
__metatable = function(...) print("metatable", ...) end
}
)

Now at first glance it seems to make sense to crash, stack overflow, so I
ran the code in a LuaJIT(latest build 32bit) shell, and it crashed as
expected.

Then I tried to run it in a Lua shell(5.1.4) and I got a stack overflow
error, no crash.

So I assume this is a specific LuaJIT issue.

Other related posts: