lua pass by reference issue

Place to get help with not working mods / modding interface.
Post Reply
CmdrKeen
Long Handed Inserter
Long Handed Inserter
Posts: 98
Joined: Tue Sep 29, 2015 9:03 pm
Contact:

lua pass by reference issue

Post by CmdrKeen »

I was under the impression that variable assignment was pass by reference for tables. However, I'm finding an issue with the following:

Code: Select all

	parse["1"]["inner"]["1"] = some_number
works properly, but the code as handled by a for loop:

Code: Select all


local values = ...
for _,v in ipairs(values) do
	parse= parse[v]
end
parse = some_number
fails to assign properly. Is there a way to parse through such a table without losing the reference?

Rseding91
Factorio Staff
Factorio Staff
Posts: 13242
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: lua pass by reference issue

Post by Rseding91 »

Passing a table around is passed by reference. Values are always values and never references.
If you want to get ahold of me I'm almost always on Discord.

CmdrKeen
Long Handed Inserter
Long Handed Inserter
Posts: 98
Joined: Tue Sep 29, 2015 9:03 pm
Contact:

Re: lua pass by reference issue

Post by CmdrKeen »

I guess my next question is parse[v] evaluated as a value then?

Rseding91
Factorio Staff
Factorio Staff
Posts: 13242
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: lua pass by reference issue

Post by Rseding91 »

You're setting the value of parse to the sub value of parse[v] so if any of [v] evaluates to a value or nil then yes it will be a value.
If you want to get ahold of me I'm almost always on Discord.

Post Reply

Return to “Modding help”