Why is one tab not being imported as a dependency?

Don’t know what Codea is written, suspect one of C incarnations, but I feel that the need for a project profiler/error trapper has been needed for some time. The current error trapping is pretty good but there are holes which could be filled. But, I believe the best way to do this is with the language that Codea is built in as all of the hooks etc will already be present and accessible by the developers.

That brings me to my second point - it should be done by @Simeon and his crew.

Third point - I think it should be a system which is configurable on/off within Codea and core code could be excluded when running through Xcode etc. Present within Codea if needed to remove troublesome issues and final test before issuing projects.

@Bri_G you’re not wrong. And I’m curious if you’ve investigated any of lua’s own error-trapping/debugging tools. They’re not super robust but they can help in some situations. But they’re no replacement for a UI-level debugging/profiling system of course, I fully agree that we could use that.

@RonJeffries as you probably sussed this is what I meant by a hacky way to solve problem 4 (too many tabs).

@UberGoober - unfortunately I’m not that good a programmer, but I have missed a few tools at times, but rather than build our own I think it better if TwoLivesLeft provided them - they probably have most of what we need now. Simple tools like FPS built in would save us time and effort.

i’d suggest that the best idea might be for @Simeon et al. to provide “hooks” in the base implementation, that could do things like call back to user-provided lua functions. then everyone could contribute to developing useful tools. there may already be some built in, but i suspect we need some special ones, such as ability to stop the program, go to the console, then resume.

there’s a lot we could do, i suspect, given some spots to hold on to.

@RonJeffries you are aware that my breakpoints do both those things — use hooks and allow callbacks — no?

Sure it would be swell if Codea provided them, but that’s exactly (I think) what I’m providing too.

Can’t use the console though. I couldn’t figure that one out. Would love help if anyone has ideas.

i have not reviewed your breakpoint stuff yet. one day, i shall. :smile:

@dave1707, @RonJeffries, about my breakpoints, I should be very clear: this is a bad solution.

It’s extremely kludgey; it’s a huge cheat that runs around Codea’s back and twists it into shapes it wasn’t meant to go.

It is no replacement for what people are calling for in this thread, which is a nice built-in, system-level set of basic debugging tools. I want to be really clear that I don’t think my breakpoints make the need for those tools any smaller at all._ Out of desperation I made something that served my needs just barely, and I really think this is not the way things should be done.

That said, a few explanations: there are two separate things happening here: the breakpoints, and the diagnostics. I invented the breakpoint system but the diagnostics are all native lua. Lua’s debug.sethook system is primitive but it allows you to declare a function that gets run at either every line, every function call, every return from a function call, or some combination of those.

So native lua, without any help from me, can provide line-by-line analysis of code. You can run it and then look at a big list of print statements, or however you stored the data you collected. The only thing it can’t do is provide it live. That’s what I did; the part I’m adding is the step-by-step.

The way I enable step-by-step is essentially put an infinite loop after every line. I use the sethook command to activate an infinite loop that does only one thing: monitor keyboard input.

This is a cheat. Codea is essentially broken at this point. You can’t interact with anything. Buttons don’t work, touches don’t get processed. You can’t use the console. It acts just like it would if it were actually stuck in a loop… because it is.

The one thing it can do is respond to keyboard input. I searched and searched for a way to break out of an infinite loop and found nothing until I looked at the keyboard API. You can’t make anything happen asynchronously in Codea (even http calls don’t get processed in parallel) except for responses to keyboard events.

So what’s happening in my step system is the sethook function processes a line, then my code hangs the whole system until the right keyboard keys are pressed, then sethook processes another line, and my code hangs the system again, and etc etc.

Now as limited as this is, it can still be extremely useful. For one thing, it prints out the function name and line number at every step. So you can watch command flow as it happens. That right there helped me enormously.

And with the function that gets passed to sethook you can perform any diagnostics you want, mostly. You can print out variables. You can do math. You can even run unit tests (in theory, I haven’t tried it). You can do anything you can do in a function. The one catch is scope. In my system you can only access global variables. You could write your own lua debugging code if you want, and include it in the callbacks my system does, because with lua’s built in tools it is possible to examine variables that are only in the scope of the current line, it’s just tricky and I don’t really know how to do it.

But with those caveats, you can do at diagnostics you want, line by line, live. This again, though limited, was extremely helpful to me. Any variables I needed to monitor I just made global temporarily.

So again my breakpoint system is no replacement for real debugging tools. It cannot (at least in any way I can figure out) let you interact with your program while you step through it. It can however expose control flow, which is extremely useful, and it can run any diagnostic function you write, live, line-by-line, which is also extremely useful—at least it was for me.

And that said, it’s a big big big big +1 from me to the call for real, baked-in, not-cheating diagnostic tools.

@UberGoober After all that I still don’t know how to do anything. It’s like the keyboard does nothing except for the tab, if I had one and qq. What are the exact steps to dump a variable because everything I try does nothing. So what’s the step by step.

where’s the version that uses hooks, i just found the one that hangs in draw.

@RonJeffries I assumed by hooks you meant the same thing lua does with the sethook command, but perhaps you don’t. Could you clarify?

@dave1707 I’ll change it so it uses a letter when I have a moment. When you say “I can’t do anything,” that’s exactly right, you can’t do anything. You can watch the code progress line by line, which lets you snoop the flow of the code, and you can write a callback that does something every line, which will most likely be to print the value of some variables. That way you can see how values are changing and at what line they’re being changed.

So if by “dump a variable” you mean print to console what its value is at every step, that’s trivial, you just pass in a function that prints that variable. Any function that you want to run at every line will run at every line.

If that’s still unclear, maybe look at the Flappy program and tell me a value you’d like to see printed to screen and the line where you want the breakpoint to start and I’ll set it up for you. Or if you prefer you could write something of your own and tell me what you want to inspect and I’ll set it up.

@dave1707 @RonJeffries I’ve updated the demo now.

The keys are now ‘t’ to step/resume and ‘q’ to turn breakpoints off altogether and go back to the running program.

I’ve also updated the instructional text and the callback functions to better demonstrate and explain what good this dang old thing is.