Debugging Augustus Loop scripts in Logic/Mainstage

Official support for: expertsleepers.co.uk
pdcawley
KVRer
9 posts since 11 Sep, 2020

Post Mon Sep 14, 2020 4:07 am

So, I'm trying to cook up a control scheme that uses long presses and multi-presses to control AL as a looper under MainStage and or Logic Pro X. I _think_ I know what I'm doing in terms of how I'm managing state and I've grabbed a tiny state machine library off Github to help with that but I'm climbing the wall trying to get debugging traces from the console. I've sprinkled print statements throughout the code, but I'm not seeing any of the output I expect. Nor am I seeing any obvious error messages.

However, if I write a suicide.lua script:

Code: Select all

thisFunctionDoesNotExist(1/0)
and place it in the script directory, it dies quietly without, as far as I can tell, emitting anything that I can find via Console.app. When I run that script on the command line, I get attempt to call a nil value ..., but searching for that string in Console finds nothing.

Am I missing something?

os
KVRian
1312 posts since 22 Mar, 2002 from UK

Post Wed Sep 16, 2020 1:00 am

I can see Lua output in the console - easier if you filter by process:
Screenshot 2020-09-16 at 10.00.21.png
You do not have the required permissions to view the files attached to this post.

pdcawley
KVRer
9 posts since 11 Sep, 2020

Post Wed Sep 16, 2020 5:48 am

I can see the lua output, no problem. What I can't see are any runtime or compile time errors; at least, not from Logic.

pdcawley
KVRer
9 posts since 11 Sep, 2020

Post Wed Sep 16, 2020 11:10 am

Right. Here's a helpful fragment of code to catch error messages and print them to the logs before rethrowing them.

Code: Select all

if debugging then
  function catch_and_rethrow(func, ...)
     local function parse_pcall_results(succ, err, ...)
        if succ then
           return table.unpack({err, ...})
        else
           print('Caught error: '..err)
           return error(err)
        end
     end
     return parse_pcall_results(pcall(func, ...))
  end
else
  function catch_and_rethrow(func, ...)
    return func(...)
  end
end
Then you can wrap function calls in like so:

Code: Select all

result = catch_and_rethrow(suspect_function, arg1, arg2, ...)
If suspect_function is throwing an error and debugging is truthy, then catch_and_rethrow will catch it, print it out using the lua 'print' function, ensuring the error message reaches the console, and then rethrow the error. If debugging is false, lua's tail call optimisation should means it shouldn't impact performance.

os
KVRian
1312 posts since 22 Mar, 2002 from UK

Post Wed Sep 16, 2020 11:00 pm

Nice, thanks.

pdcawley
KVRer
9 posts since 11 Sep, 2020

Post Wed Sep 16, 2020 11:27 pm

I tracked my problem with the state machine library down to the fact that the lua I was testing it with on the commandline had 'table.unpack', but the lua in AL is an older version that has 'unpack' in the global namespace. Quite tricky to track down when errors weren't being reported.

Return to “Expert Sleepers”