Sorry, we don't support your browser.  Install a modern browser

metatable is lost when a table is returned by call function#3172

V

When a table is returned from a function, if the function is called from another object thanks to https://api.tabletopsimulator.com/object/#call , then metatable data are missing from the returned table

to reproduce :
in Global script :

function getTableWithMeta()
  return setmetatable({"foo","bar"},{__index = function() return "unknown key" end})
end
function onLoad()
  local tt = getTableWithMeta()
  print(logString(tt))
  print(logString(getmetatable(tt)))
  print(tt.foo)
end

output =

1: foo
2: bar
“__index”: <func>
unknown key

in any object script :

function onLoad(save_state)
  local tt = Global.call("getTableWithMeta", {})
  print(logString(tt))
  print(logString(getmetatable(tt)))
  print(tt.foo)
end

output =

1: foo
2: bar
nil
nil

3 hours ago