Simon Schick wrote: > 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. LuaJIT limits recursion depth by checking for the number of elements in the Lua stack, not by the number of frames. That allows a much higher recursion depth than Lua. But it looks like the default C stack on Win32 is rather small. So for this example the C stack overflows before the Lua stack overflows. A Lua stack overflow would be caught and properly reported. But a C stack overflow leads to a crash. I'm not sure how to check for this case or how to avoid this in general. There are various other ways to overflow the C stack, so just fixing this one case doesn't do much. There's no way to predict how much C stack is left, because that depends on the OS and how much is consumed by the hosting C program or by called C functions. Basically, any C function that can be called from Lua and calls back into Lua could potentially be used to overflow the stack, given the right circumstances. --Mike