Andreas,
Can you confirm this for me please..
Have been writing some metamethods and have come across an issue that might be a bug.
Take note of the line where dummy=0 if this is removed in either of the Object.copy or Object.union functions the system goes into a loop and does not return. You can still close using the close gadget. This line can be anything as long as it is not next which closes the for loop. The Object.tostring function did not present this symptom because it has the sep=", " statement between endif and next which stops it from stalling.
Regards,
Dwayne
Code: Select all
Object={}
function Object.copy (o)
local ret={}
local k, v
local dummy
for k, v in pairs (o)
if (gettype (v)=#TABLE)
ret [k]=Object.copy (v)
else
ret [k]=v
endif
dummy=0
next
return (ret)
endfunction
function Object.union (t1, t2)
local ret=Object.new (object, {})
local k, v
local dummy
for k, v in pairs (t1)
if (gettype (v)=#TABLE)
ret [k]=Object.copy (v)
else
ret [k]=v
endif
dummy=0
next
for k, v in pairs (t2)
if (gettype (v)=#TABLE)
ret [k]=Object.copy (v)
else
ret [k]=v
endif
dummy=0
next
return (ret)
endfunction
Function Object.tostring (o)
local s="{"
local sep=""
local k, v
for k, v in pairs (o)
s=s .. sep .. k .. "="
if (gettype (v)=#TABLE)
s=s .. Object.tostring (v)
elseif (gettype (v)=#FUNCTION)
s=s .. "function"
else
s=s .. v
endif
sep=", "
next
return (s .. "}")
EndFunction
Function Object.print (o)
nprint (Object.tostring (o))
EndFunction
Function Object.new (this, o)
local object=o
setmetatable (object, this)
this.__index=this
this.__add=this.union
return (object)
EndFunction
a=Object.new (object, {a=1, b=2, c=3, g={1}})
b=Object.new (object, {d=4, e=5, f=6, debug=function () print ("Hello
World!") endfunction})
a.print (a)
b.print (b)
c=a + b
c.print (c)
a.g={3}
a.print (a)
c.print (c)
waitleftmouse