Passing an array name to a function, then filling it in

I would like to call a function that takes data and then populates an array that I call in one of the function parameters. An example of what I'm looking for:

function readSaveFile(saveFileName, arrayName)
    if love.filesystem.exists(saveFileName) then
        arrayName = Tserial.unpack(love.filesystem.read(saveFileName))
    end
end

      

The problem is that instead of creating an array with a string named arrayName, it replaces the parameter with an array explicitly named "arrayName". Is there a way that I could fill in the specified array name?

+3


source to share


1 answer


You can always insert data into a given array (provided it is non-zero). For example:



function readSaveFile(saveFile, arrayName)
  if love.filestystem.exists(saveFileName) then
    for k, v in pairs(love.filesystem.read(saveFileName)) do
      arrayName[k] = v
    end
  end
end

      

+4


source







All Articles