This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
ArqiTek's profile picture

Lua Debug Library in CC?

Started by ArqiTek, 29 October 2015 - 02:01 PM
ArqiTek #1
Posted 29 October 2015 - 03:01 PM
Is lua's debug library implemented in CC? I was hoping to use debug.getinfo to improve traceability.

My code's pretty heavy on the coroutines so when a function parameter is mishandled higher up the stack the default trace usually doesn't cut it. error(_,level) has been helpful but it would be nice to avoid having to throw exceptions whenever there's a problem…
Lyqyd #2
Posted 29 October 2015 - 03:23 PM
Nope, the debug API is purposely disabled, as exposing it would break the sandbox's internal walls between the computers.
SquidDev #3
Posted 29 October 2015 - 03:25 PM
If you are running on a local world, CCTweaks adds an option to enable the debug api (add "debug" to globalWhitelist in the config) - though obviously don't do this on a server.

If you just want to trace, you can get the current function + line through pcall and error:

local _, func = pcall(error, "", 2)

 -- Or even:
print(select(2, pcall(error, "", 2))
Edited on 29 October 2015 - 02:27 PM