Page 1 of 1
DeepCopy
Posted: Tue May 03, 2016 8:16 pm
by NoriSilverrage
Does anyone know why this works:
local lr1 = util.table.deepcopy(data.raw["transport-belt-to-ground"]["basic-transport-belt-to-ground"])
But this doesn't?
local lr1 = deepcopy(data.raw["transport-belt-to-ground"]["basic-transport-belt-to-ground"])
I setup a few deepcopy entries and they were working fine with the modlist I had. However, I discovered that if I removed every mod, all of a sudden the above didn't work (erroring on deepcopy) and I had to add the util.table. part to it.
Re: DeepCopy
Posted: Tue May 03, 2016 8:44 pm
by Choumiko
Not sure how sandboxing in data.lua works, but this sounds like some mod added a deepcopy() function
Re: DeepCopy
Posted: Tue May 03, 2016 10:12 pm
by orzelek
Choumiko wrote:Not sure how sandboxing in data.lua works, but this sounds like some mod added a deepcopy() function
Original function is table.deepcopy. Other one is added by one of mods loaded before your mod - all those are visible to all lua users unless they have local specifier (AFAIK).
Re: DeepCopy
Posted: Tue May 03, 2016 10:48 pm
by Adil
Nope, it just cannot be so. It'd be a total wreck with nameclashes. Also, there is a reason modders have to use remote.-module to communicate between the modules.
I won't be able to track a quote but someone from the devteam said that every mod is sandboxed in its own confinement. As I've tested right now, even commonly required files are loaded for mods as independent copies.
@NoriSilverrage
I just cannot understand what situation exactly is happening in the op.
Can't you just find out which mod exactly allowed that code to work?
Re: DeepCopy
Posted: Tue May 03, 2016 11:11 pm
by NoriSilverrage
Hmm, I'm not really sure. If I remove boblogistics it errors. But I see no reference to deep copy in any of his files... But oddly if I have that mod plus boblibrary, it still throws a error.
Oh well. At least I know the proper deep copy.
@Adil - Name clashes? That deepcopy command doesn't show the rest of the file which renames that local variable. So no duplicates.
Thanks for the answers
Re: DeepCopy
Posted: Wed May 04, 2016 1:24 am
by Adil
NoriSilverrage wrote:@Adil - Name clashes? That deepcopy command doesn't show the rest of the file which renames that local variable. So no duplicates.
That refers to function names. If every mod did put it's stuff into shared environment, they'd might have quite a bunch or same named functions and global variables. Then those would be overwritten and only last mod would be functional at best.
Re: DeepCopy
Posted: Wed May 04, 2016 7:21 am
by orzelek
Adil wrote:NoriSilverrage wrote:@Adil - Name clashes? That deepcopy command doesn't show the rest of the file which renames that local variable. So no duplicates.
That refers to function names. If every mod did put it's stuff into shared environment, they'd might have quite a bunch or same named functions and global variables. Then those would be overwritten and only last mod would be functional at best.
Please take a look at how bob's library mod works - it simply defines the functions and mods that load after it can use them.
There is no 100% sandbox - each mod has it's own global table but funciton space is the same.
Re: DeepCopy
Posted: Wed May 04, 2016 7:41 am
by DaveMcW
data.lua is global.
control.lua is sandboxed.
Re: DeepCopy
Posted: Tue May 10, 2016 10:33 am
by bobingabout
There's a reason I use the bobmods. prefix, it's so that I can keep my variables and functions organised so they don't conflict with other mods.
Though, some of my older functions that are included directly in the mod just have a bob_ prefix. Same reason, but not as secure.
Still... None of my mods add a deepcopy() function, I can't be sure if I've ever even used it (Yet. Though I do see why it would be useful), in most of the situations I've seen deepcopy() being used, I either just use a = (Because being a copy, or referencing the original doesn't matter, it's usually done in cases where the original is discarded), or use a function that returns the table (A table defined in raw data, meaning it is constructed every time the function is called, meaning every instance is a unique copy of the table)
Re: DeepCopy
Posted: Thu Jan 23, 2025 5:30 pm
by SpaceBroetchen
Hey there,
My answer might be a bit late, but I am able to confirm that in the data phase mod sandboxes are shared. aai-containers seems to use in prototypes/combined/containers.lua the table.deepcopy() function (L. 325). I have not found a definition for it in this mod but I found one in core/lualib/util.lua (L. 6) which gets always loaded before all other mods. This might be the one you are using.