Add a debug hook to any LL library function
Frionil Fang
The ll table is frozen, but it can be cloned and modified to enable a debug mode that lets you track function calls or perform other tricks.
SCRIPTDEBUG = true
if SCRIPTDEBUG then
llDEBUG = ll -- store original ll table reference
ll = table.clone(ll) -- replace with modifiable version
-- then modify the function with debug info; calls original function afterwards
ll.Say = function(c, s) llDEBUG.OwnerSay(`(DEBUG:Say at line {debug.info(2,'l')-1})`); llDEBUG.Say(c, s) end
end
ll.Say(0, "test")
This of course costs a considerable chunk of memory as per gcinfo(), so it may not be tenable if/when harder memory limits set in.
Log In
Signal Linden
Very nice! If you want to avoid cloning the entire table (as you'll probably want to to save memory) you can also use a metatable to an empty table with
ll
as the __index
so it will use the underlying ll
table if a field doesn't exist on your object. This is similar to how we handle sandboxing of user-mutable globals while still allowing you to shadow their values, for example:-- Replace `ll` library with a mutable overlay, indexing into the base version for missing keys
ll = setmetatable({}, {__index=ll})
function ll.Say(channel, val) print(`hooked! {val}`) end
-- Can use the replaced function
ll.Say(0, "foo")
-- Still able to get functions from the underlying table
print(ll.Abs(-2))