Skip to content

Instantly share code, notes, and snippets.

@zorggn
Last active December 8, 2015 19:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zorggn/ca59b135c596a780c219 to your computer and use it in GitHub Desktop.
Save zorggn/ca59b135c596a780c219 to your computer and use it in GitHub Desktop.
Lua hax #84721365: Calling plain tostring in custom tostring metamethod to get table address.
local t = {}
local toString = function(t)
local original = getmetatable(t)
local modified = {}; for k,v in pairs(original) do modified[k] = v end; modified.__tostring = nil
setmetatable(t, modified)
local address = tostring(t):sub(8)
setmetatable(t, original)
return string.format("Identifying table:\n%s\nYep, it's a table.", address)
end
setmetatable(t,{__tostring = toString})
print(t)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment