Coroutines and Hooks

Is there a way to set a hook containing coroutine.yield to a coroutine? It doesnt seem to work, in my experience. Ive tried everything, but im guessing theres just something im missing

What is it you’re trying to do? Could you give us a bit more context, maybe some code?

For instance:

func = function() for i=1,1000 do print(i) end end
co = coroutine.create(func)

this works, but every call to coroutine.resume restarts the whole thing

I don’t know what you’re trying to do, what’s the aim here? coroutine.yield would normally go inside the function, i.e. inside the for loop.

I want it to yield after every single line without having to put coroutine.yield in there a million times. The actual function im using is much longer than that example function.

Is this for a debugger/ tracer?

That was the idea; it seems all such projects were dropped by those working on them

The best debugger/tracer I use is just plain old print statements. They don’t show as much as a real debugger/tracer, but they always got the job done.

True, but it’d be nice to have the real deal, I think.

EDIT: im getting mixed results on the internet; some say that it now works with debug.sethook in lua 5.2 if you do it right, and some say it only works with a C hook

@Toffer has a debugger on Codea Community called Pimp My Print. Unfortunately it uses setfenv so it doesn’t run on Lua 5.3 in its current state

I have another Lua app compiler and if I run a version of this code with that compiler, every time it executes the debug.debug command, the program stops and let’s me enter commands to print variables, change variables, etc. When I type ‘cont’, the program executes to the next debug.debug command and stops. Unfortunately, this code doesn’t work with Codea. Codea ignores the debug.debug command and runs the program to completion.

function setup()
    a = 0
    while a < 5 do
        a = a + 1

I know, i got very excited when i found debug.debug in package>>loaded and in te Lua reference, but Codea does indeed ignore the command, much to my dismay. It was nearly as exciting and disappointing as that time I thought string.dump returned a string representation of a function, or that time background stopped accepting non-integer numbers

You can get a string representation of a function with debug.getinfo(functionName).source