Hi,
would it be not to difficult to implement a deep and/or shallow copy in ZScript?
Would be handy when copying instances instead of copying each property.
(some more explanation: I have a case where I can't use structs because the objects are part of dynamic arrays)
ZScript Deep and/or shallow copy
Moderator: GZDoom Developers
- Major Cooke
- Posts: 8175
- Joined: Sun Jan 28, 2007 3:55 pm
- Preferred Pronouns: He/Him
- Location: QZDoom Maintenance Team
Re: ZScript Deep and/or shallow copy
Can you elaborate? Not sure what 'deep' and 'shallow' copying refers to.
- Arctangent
- Posts: 1235
- Joined: Thu Nov 06, 2014 1:53 pm
- Contact:
Re: ZScript Deep and/or shallow copy
They're table duplication functions. shallowcopy is non-recursive, so tables within tables won't be fully copied, while deepcopy is, allowing for full but most costly duplication.
I have no idea if they'd be relevant in the slightest to ZScript.
I have no idea if they'd be relevant in the slightest to ZScript.
- gwHero
- Posts: 360
- Joined: Mon May 08, 2017 3:23 am
- Graphics Processor: Intel with Vulkan/Metal Support
- Location: The Netherlands
Re: ZScript Deep and/or shallow copy
This link about .Net shallow/deep copy explains it rather well: http://net-informations.com/faq/net/sha ... p-copy.htm
For reference types, you cannot just copy an instance. At the moment I have this code:
All properties of the object are copied. A shallow or deep copy would do this for you, which is not only shorter and easier, but also bug preventing when the class definition is changed and the programmer forgets to adjust the custom copy method.
For reference types, you cannot just copy an instance. At the moment I have this code:
Code: Select all
MAlbumEntry ObjectCopy(MAlbumEntry iObj)
{
MAlbumEntry oObj = new("MAlbumEntry");
oObj.cname = iObj.cname;
oObj.levelnum = iObj.levelnum;
oObj.PlayerX = iObj.PlayerX;
oObj.PlayerY = iObj.PlayerY;
oObj.PlayerZ = iObj.PlayerZ;
oObj.playerAngle = iObj.playerAngle;
oObj.playerPitch = iObj.playerPitch;
oObj.floorPic = iObj.floorPic;
oObj.ceilPic = iObj.ceilPic;
oObj.secbrightness = iObj.secbrightness;
oObj.rainx = iObj.rainx;
oObj.rainy = iObj.rainy;
oObj.rainz = iObj.rainz;
oObj.fadecolor = iObj.fadecolor;
return oObj;
}