Advanced

Re: Debugging a script?

Debugging a script?
June 02, 2023 03:14AM
I sort of already know the answer - but I'm wondering if anybody has come up with a way to use a 'real' debugger to debug checker scripts (ie. running locally)? Sometimes printf debugging just isn't that easy. Being able to set breakpoints and inspect variables would be extremely helpful in some situations.

It's easy enough to add a 'bootstrap' script, which will provide the PGC methods, to your target script, and run that locally in a debugger. However, the real problem is accessing data that would be returned by those methods (eg. GetFinds()). You could obviously add a script to scrape some data out of the database, but that seems pretty cumbersome given the 100k log limit (and ... questionable given those checkboxes I check when creating new scripts :)).
Re: Debugging a script?
June 23, 2023 05:50PM
So, I did a little experimenting... and it seems not impossible.

With VSCode, and this plugin (both free): https://marketplace.visualstudio.com/items?itemName=actboy168.lua-debug, you can debug lua. It seems to come with built-in Penlight ('Date') class. You create a script called bootstrap.lua (or whatever you want), and make the default launch load that.

bootstrap.lua
-- Include penlight, which includes Date, etc.
require("pl.init")

-- The script_input.lua file contains the parameters for the input...
require ("script_input")

-- Define the PGC interface (most of which is not implemented)
Interface = {}

function Interface:new(o)
	o = o or {}   -- create object if user does not provide one
	setmetatable(o, self)
    self.__index = self
    return o
end

function Interface:GetFinds (profileId, params)
 	-- Returns an associative array with the finds from given profileId. More...
	error("Not implemented")
end

function Interface:GetHides (profileId, params)
 	-- Returns an associative array with the hides from given profileId. More...
	 error("Not implemented")
end

-- ... continue with all the API functions

PGC = Interface:new()
args = { { profileId = script_input[2], profileName = script_input[3], gccode= script_input[4], config = script_input[5], } }

local result = require(script_input[1])

script_input.lua
script_input =
{
	"blah", -- the name of the script on disk you want to debug.
	12345, -- profileId
	"bmuzzin", -- profileName
	"GC12345", -- gccode        
	{ -- "config" parameter
		debug=true,
	}
}

Inside your actual script, usually the first thing that is done is get the input parameters. To work both locally and on PGC, this needs to be changed to:
local args = args or {...} -- used to be just {...}

Now, the first benefit this (minimal) setup gets you is that, you'll know whether your script will execute without an exception. When I'm developing a script, usually I need to modify it several times on PGC before it doesn't have any typos, etc. in it. So, small win there, because editing the script locally is much faster.

But! You can also debug in an actual debugger, that is, until you hit a call to the PGC interface (which will then error out). I'm planning on adding support for some of these interface functions, so that a small subset of the API can be used. The most useful function used by scripts is GetFinds - and my thought there is to make a GSAK -> lua conversion, so you would just get the GSAK database you have downloaded to work as a dataset.

I can update this thread if others are interested in the progress.
Sorry, you do not have permission to post/reply in this forum.