Skip to content

Commit

Permalink
Added line number to debug breakpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
mario-deluna authored Feb 15, 2024
1 parent ea1d207 commit 8b146dc
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/SiliconConsole.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,18 @@ public function getExposedFunctions(LuaContext $ctx) : ?array
*
* Console logs the given value. and stops the lua execution.
*/
'debug' => function($args) {
'debug' => function($args, $trace) {

// we only really care about the second line in the trace
$trace = explode("\n", $trace)[2] ?? '';
// try to parse the line number
preg_match("/\[string \"SiliconEval\"\]:([0-9]+):/", $trace, $matches);
$line = $matches[1] ?? 0;

// always drop the argument count, not needed in PHP
unset($args['n']);
$this->logInfo(...$args);
$breakpoint = new SiliconRuntimeDebugBreakpointException("Debug breakpoint");
$breakpoint = new SiliconRuntimeDebugBreakpointException("Debug breakpoint [line: $line]");
$breakpoint->setBreakpointValues(array_values($args));
throw $breakpoint;
},
Expand All @@ -68,8 +74,10 @@ public function preloadLua() : ?string
function log(...)
console.log(arg)
end
_debug = debug
function debug(...)
console.debug(arg)
local trace = _debug.traceback()
console.debug(arg, trace)
end
LUA;
}
Expand Down

0 comments on commit 8b146dc

Please sign in to comment.