Hi Retwulf. I agree with Neikun that we could probably be more helpful with a more specific example.
FYI, stack overflow in lua most commonly occurs in "infinite" recursion scenarios, but not all "infinite" recursion results in stack overflow. Unfortunately, the deciding factor is a detail of the underlying lua implementation, so it might not make much sense to folks like us who just use lua as an embedded scripting language in another application (Grimrock.)
This code will generate a stack overflow error, which terminates the overflowing process and allows you to continue your session in the editor:
Code: Select all
overflow = function()
local x = 12
overflow()
return x
end
overflow()
This code will not generate a stack overflow error, but it will run indefinitely without returning control to the editor. This generally requires me to open task manager to kill my editor session, losing all unsaved work:
Code: Select all
overflow = function()
local x = 12
return overflow()
end
overflow()
In both cases, calling overflow will call overflow will call overflow... The critical difference is that in the first code, lua has to keep track of local x while it calls overflow recursively. Each call to overflow has its own copy of local x in a piece of memory called "the stack", and eventually these copies fill up and overflow the (finite) stack. In the second code example, lua realizes that it doesn't have to keep track of x during the recursive call, so it doesn't. This is called "proper tail calling" in lua jargon.
In conclusion, a "stack overflow" error points to a very specific kind of bug in the mod you're trying to load. More details about the mod, and which version of Grimrock you're running could help.
