[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Copying objects



Is there a "clean" way to make a copy of an object. The best I could do for a
nice easy case with no pointers or object references in the class was:

pro Object1::set_all, tstr
for i = 0, n_tags(tstr)-1 do self.(i) = tstr.(i)
end

function Object1::copy
temp = {object1}
for i = 0, n_tags(temp)-1 do temp.(i) = self.(i)
newobj = obj_new('object1')
newobj -> set_all, temp
return, newobj
end

While it works,  it seems to be a bit of a kludge. Is there a better way?

James
-- 
+------------------------+-------------------------------+---------+
| James Tappin           | School of Physics & Astronomy |  O__    |
| sjt@star.sr.bham.ac.uk | University of Birmingham      | --  \/` |
| Ph: 0121-414-6462. Fax: 0121-414-3722                  |         |
+--------------------------------------------------------+---------+