metatable - Is it possible to bypass __tostring the way rawget/set bypasses __index/__newindex in Lua? -


for example:

local my_table = { name = "my table" } local my_table_mt = {}  function my_table_mt.__tostring(tbl)     return "%s<%s>":format(tbl.name or "?", rawtostring(tbl)) end 

is possible? know rawtostring method doesn't exist, there possibly way emulate behavior, or bypass altogether?

there kludge:

function rawtostring(t)    local m=getmetatable(t)    local f=m.__tostring    m.__tostring=nil    local s=tostring(t)    m.__tostring=f    return s end 

Comments

Popular posts from this blog

javascript - Confirm a form & display message if form is valid with JQuery -

Retrieving ETA (estimated time of arrival) with Google Distance Matrix API and public transit as transport mode -

ionic framework - Meteor - Error: Failed to execute 'insertBefore' on 'Node' -