Guy
New Member
Posts: 18
|
Post by Guy on Nov 30, 2017 8:37:07 GMT
garbage collection isn't the issue with your code, you have infinite recursion and you definitely don't have proper tail calls
|
|
Guy
New Member
Posts: 18
|
Post by Guy on Dec 2, 2017 20:20:03 GMT
What exactly is the feature you want? Callback functions or a change in the garbage collection? If it's either of those, they're language specific, so your requests can't be fulfilled here, but let's continue. I'm gonna bring up a few points and they'll be based off the code you've offered. Maybe they'll help, maybe not. Skip to #4 first, if that doesn't help, start at #1
1. So what happens when we run that code? It results in a stack overflow
2. So what does this mean? What does it have to do with garbage collection? Lets take a look at the pieces of your code that causes a problem
function original () if secondary() ~= third() then return original () end end
function secondary() return original () end
When you execute original, the if statement executes secondary. At this point in time, the stack is increased by 1. What happens next? secondary executes original again, where it reaches another if and goes around again and again, increasing the depth of the stack until it overflows. The stack's job is to keep track of where functions are supposed to return the control flow and the stack is working just fine, but your code is not. So what does this have to do with garbage collection? Nothing, this isn't a problem for garbage collection to deal with
3. If you're requesting callback functions. Lua can do those
4. My final point and probably the most helpful to you. If you want to return a function itself but not execute it, e.g. use return foo, not return foo()
|
|
Guy
New Member
Posts: 18
|
Post by Guy on Dec 4, 2017 12:59:22 GMT
|
|
Ollie
New Member
Posts: 40
|
Post by Ollie on Dec 23, 2017 5:17:33 GMT
It means lua_checkstack() just, trust me
|
|