I'm trying to create copies of a class instance using table.shallowcopy
or table.deepcopy
which both fail in different ways.
shallowcopy
loosely "fails" because it doesn't copy the metatable, which is perhaps intentional, but isn't super obvious, especially to someone who might not even know that metatables exist:
import "CoreLibs/object"
class("A").extends()
local a = A()
local aCopy = table.shallowcopy(a)
print("a = ")
a:tableDump()
-- setmetatable(aCopy, getmetatable(a))
print("aCopy = ")
aCopy:tableDump()
With line 8 commented, we get a failure because tableDump
isn't defined:
a =
super (A):
aCopy =
main.lua:10: method 'tableDump' is not callable (a nil value)
stack traceback:
main.lua:10: in main chunk
With line 8 uncommented, everything works as desired.
However, when I change it to deepcopy
, the entire simulator just crashes:
import "CoreLibs/object"
class("A").extends()
local a = A()
local aCopy = table.deepcopy(a)
This is surely not intentional! I'm running on a MacBook Pro M2 Max on Sonoma 14.2 with SDK 2.2.0.