This utility enables the integration of breakpoints into Solar2D projects. Breakpoints are essential for debugging, allowing developers to pause execution and inspect variables at specific code locations. Solar2D does not natively support breakpoints, and this tool provides a workaround to simulate this functionality.
-
Download: Obtain the
breakpoints.lua
file from this repository. -
Add to Project: Incorporate the file into your Solar2D project.
-
Include in Code: Import
breakpoints.lua
in yourmain.lua
or in other Lua files where debugging is required.require("breakpoints")
Insert the following line at the desired points in your code to set a breakpoint:
breakpoint(id, fn)
id
(number): A unique identifier for each breakpoint within a file.fn
(function): A callback function for inspecting variables when the breakpoint is triggered.
Upon reaching a breakpoint, the Solar2D simulator pauses execution, and the console displays the line where the breakpoint was set. To inspect or modify variables, you need to edit the callback function in your code file directly.
- Edit and Continue: Modify the callback function to inspect or change the values of variables. After making changes, ensure the callback function returns
true
and save the file (Ctrl+S
) to continue execution.
Note: The scope of variables is fixed once the file is loaded. You cannot introduce new variables at the breakpoint; you can only manipulate variables that already exist in the function's scope.
local function doSomeWork()
local x = 10
local y = 20
local z = x + y
breakpoint(1, function()
print("x: " .. x) -- Inspect x
print("y: " .. y) -- Inspect y
print("z: " .. z) -- Inspect z
return true -- Continue execution after inspection
end)
print("The sum of x and y is: " .. z)
end
doSomeWork()
Creator: Depilz
Company: Studycat Limited
This tool is distributed as open-source under the MIT License, allowing for modification and redistribution. We encourage enhancements and would love to see how you adapt it for your needs.