Custom error traceback

How can I properly debug compiled Lua? For example if there is error in compiled code:

-- Compiled code
function comp_fooBaz(some, args)
    local y = 1
    doStuff()
    x += 4 -- Error in line 5, function "comp_fooBaz
end

It doesn’t match original line, function name etc:

-- Pseudo code
fooBaz ->
{
    (some, args)
    y = 1
    x *** 4 -- Error in line 6, function fooBaz
}

How do I set func name, lineno to my own to make error messages more readable? Is this possible?

I’m not quite sure of what’s the context for this, but anyways, compiling sometimes implies sacrificing readability and specially debuggability. In most cases, it isn’t about making your compiled code match the original one but having a good mental map of what you’re doing.

In this case, the error may be from the x being something other than a number.

Yes, I know. The error is intended. I just want to change traceback from function comp_fooBaz, line #5 to function fooBaz, line #6.

There’s no practical way of doing that. You can try and rewrite the code in some different manner, add a space between statements… There’s not a real need for lines to match from code sample to code sample.

But how to debug compiled code then?

As I said, you have to keep track of your code’s logic and understand which part of the code applies in each case.

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.