Is it possible to bypass 'stack overflow'?

  1. What do you want to achieve?
    I want to bypass the stack restriction so I can use recursive functions without erroring.

  2. What is the issue?
    Attempting to go over the limit wich would be 16380 (on studio) would error for me.

  3. What solutions have you tried so far?
    None. I have tried to search a solution but didn’t find it.

My question is, is it possible to bypass or go over the limit? If so, how would I go about doing this?

There’s a limit for a reason. Doing so could harm your game due to the sheer amount of information.
Just so you know, you don’t have to include the questions in your post, and please attempt to solve it yourself before posting.

He said he searched for a solution but didn’t find it,

if I called a recursion with wait() after calling the function again it would give a stack overflow, if I managed to bypass that I’d probably be travelling faster than time itself so yeah, the answer is no.

call the wait before calling the function basically, that should fix your stack overflow.

1 Like

I know, but it’s best to attempt to solve it without a google search or anything. It helps you learn and you could potentially find a solution.

I don’t know where to start from, that’s the problem.

Take some time to brainstorm. In my opinion, it’s the best way to solve a problem.

Hopefully I don’t have to say it again but,

local function rec()
      rec()
      wait()
end

would give a stack overflow because you are calling the wait after the function which is calling it REALLY fast,

local function rec()
      wait()
      rec()
end

that should bypass the stack overflow since its being called after waiting, thats like saying while true do wait() rather than wait() while true do

I’m using lua, not roblox lua.

It’s a good question–If you use a tail call, that is commonly optimized to use goto–Not sure about
the version of Lua you are using, but some versions do indeed do tail call optimization.

1 Like

So I took a look at lua-users and lua.org to understand more and found out where to start from and how to optimize it. Thanks.

Just so you know that what you said is completely false. The problem is regarding stack overflow, not script execution timeout. Stack overflow is caused when you exceed the size of the stack.

This code below would cause a stack overflow, since the function rec recursively calls it self over and over, creating more more than 16381 stack frames in the stack and thus causes a stack overflow.

local function rec()
      rec()
end

rec()

Yielding will just cause the stack overflow to occur slightly after some time, that’s it.

3 Likes