@@ -74,6 +74,8 @@ local config = {
7474 environment = nil ,
7575 server_name = nil ,
7676 no_detour = {},
77+ capture_locals = true ,
78+ capture_upvalues = false ,
7779}
7880
7981--
@@ -407,8 +409,12 @@ local function sentrifyStack(stack)
407409 local ret = {}
408410 for i , frame in ipairs (stack ) do
409411 local vars = {};
410- formatStackVariables (frame [" upvalues" ], vars );
411- formatStackVariables (frame [" locals" ], vars );
412+ if (config [" capture_upvalues" ] and frame [" upvalues" ]) then
413+ formatStackVariables (frame [" upvalues" ], vars );
414+ end
415+ if (config [" capture_locals" ] and frame [" locals" ]) then
416+ formatStackVariables (frame [" locals" ], vars );
417+ end
412418
413419 ret [i ] = {
414420 filename = frame [" source" ]:sub (2 ),
@@ -434,32 +440,32 @@ local function getStack()
434440 break ;
435441 end
436442
437- local locals = {}
438- local upvalues = {}
439-
440443 if (info .what == " Lua" ) then
441- -- Capture locals
442- local i = 1
443- while true do
444- local name , value = debug.getlocal (level , i );
445- if (not isstring (name )) then break ; end
446-
447- if (# name > 0 and name [1 ] ~= " (" ) then -- Some locals are internal with names like "(*temporary)"
448- locals [name ] = value == nil and NIL_REPLACEMENT or value ;
444+ if (config [" capture_locals" ]) then
445+ local locals = {}
446+ local i = 1
447+ while true do
448+ local name , value = debug.getlocal (level , i );
449+ if (not isstring (name )) then break ; end
450+
451+ if (# name > 0 and name [1 ] ~= " (" ) then -- Some locals are internal with names like "(*temporary)"
452+ locals [name ] = value == nil and NIL_REPLACEMENT or value ;
453+ end
454+ i = i + 1
449455 end
450- i = i + 1
456+ info . locals = locals ;
451457 end
452458
453- -- Capture upvalues
454- for j = 1 , info .nups do
455- local name , value = debug.getupvalue (info .func , j );
456- upvalues [name ] = value == nil and NIL_REPLACEMENT or value ;
459+ if (config [" capture_upvalues" ]) then
460+ local upvalues = {}
461+ for j = 1 , info .nups do
462+ local name , value = debug.getupvalue (info .func , j );
463+ upvalues [name ] = value == nil and NIL_REPLACEMENT or value ;
464+ end
465+ info .upvalues = upvalues ;
457466 end
458467 end
459468
460- info .locals = locals ;
461- info .upvalues = upvalues ;
462-
463469 stack [level - 2 ] = info ;
464470
465471 level = level + 1 ;
0 commit comments