Can you output the pointers of variables?

Repost; Was wondering if this was possible

1 Like

Could you elaborate more so I can understand better on what you are trying to achieve?

Well I’m not trying to achieve anything, I was just wondering if you can print the address of the memory allocated whenever you declare a variable (i.e 0x77ff09a04)

Pretty sure this is not possible for most variables. Also there isn’t really a use case for this.
However I think that using tostring() on a function like so tostring(f : () -> ()) will return the address of that function, so you could just call print(f) because print calls tostring() for you.

Hm so you propose that using tostring() on a function can potentially return the address?

Yes. I just tried it. It also works on tables with no __tostring metamethod, but you can’t just call print(t : {}) on those because Roblox will print out the contents of the table instead.
But it doesn’t return just the address, it returns the address prefixed with 'table: ’ or 'function: '.

Thank you for the help my goodman :+1:

1 Like
local function f(var : {} | () -> ()) : string
	local type = typeof(var)
	local str : string = ''
	if (type == 'table') then
		local mt = getmetatable(var)
		setmetatable(var, {})
		str = tostring(var)
		setmetatable(var, mt)
	end
	if (type == 'function') then
		str = tostring(var)
	end
	return str:split(type..': ')[2]
end

For anybody interested in this topic, here is a helper function I made to get the address of a table or a function.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.