Capturing Lua console errors on a device

I have encountered apparent bugs in my Lua code while testing on a device. I often have difficultly recreating the problem on my workstation to isolation the problem.

Is there a way to capture Lua errors and write them to a file so that I can use Xcode to download it?

Is there another way to see the Lua errors on the device? Ideally, there should be a runtime event that I can listen to and do what I want with the error information.

Mike [import]uid: 101075 topic_id: 28349 reply_id: 328349[/import]

Oops. I found a console in Xcode while the device is attached. It has the one liner for the error. [import]uid: 101075 topic_id: 28349 reply_id: 114516[/import]

In Xcode you can use the Organizer. Open Xcode, got to Windows->Organizer, in the new window you should see your device on the left hand side with a hopefully green light. Click on console and that should be your Print logs + crash logs.

You can also take advantage of the malleability of the lua interface and override print. While this still won’t get you errors, doing something like this:

local file, err = io.open(system.pathForFile(fileName, system.TemporaryDirectory), "w+")  
if file then  
 file:setvbuf("no")  
 print = function(...)file:write(table.concat({...}, "\t") .. "\n") end  
else  
 print(err)  
end  

will mimic the print() call parameters, but instead of sending it to stdout, it’ll write it to a file of your choosing. If you store the old print call, you can set it to do both logging methods as well. This will not effectively catch the errors, but you can hook up your code to have appropriate logs where the errors should be.

One downside is that I believe Corona Indie/Pro strips all your debug symbols, meaning you are likely to end up seeing that variable “?” on line “?” in file “?” was nil, which is horribly ineffective for tracking issues. I’m not sure if there is a good way in Corona Indie/Pro to be able to prevent luac from stripping your debug symbols. [import]uid: 134101 topic_id: 28349 reply_id: 114519[/import]