Inspect self while debugging?

Is it not possible to inspect the contents of self of a script in any way?

I can’t remember, but you cannot pprint self right? Hmm, yes, iterating self is not possible. https://stackoverflow.com/a/43689362

Is this the same reason, why self content is not visible in debugger variables?

image

Correct!

1 Like

I just attempted this in a script:

function init(self)
    local _self = {self}
    mt = {
        __newindex = function(t, k, v)
            t[1][k] = v
            rawset(t, k, v)
        end
    }
    setmetatable(_self, mt)
    _self.f = 01
    pprint(_self)
end

And it gave me the following output:

DEBUG:SCRIPT: 
{ --[[000001FD5E4963B0]]
  1 = Script: 0x01fd5e49dfb0,
  f = 1
}

I think this combined with tracking the table changes (I don’t know how to do it yet since I haven’t read up on it yet ), a self-inspection utility module is possible while keeping dynamic assignments fairly straightforward. Possible there’s a weird gotcha in there somewhere, though?