1

I am new to lua and encountered the following piece of code

    function X()
        local function Y() ... end
        local var1 = {var2=Y}
        ...
        return blah
    end

What does local var1 = {var2=Y} do/mean here?

Thanks!

Sarwagya
  • 166
  • 11

1 Answers1

0

Jumped the gun on this one. Seems like it simply declares an associative array (table) with key as "var2" and value as Y. Equivalent to the following:

local function Y() ... end
local var1 = {}
var1['var2'] = Y

More details here: How to quickly initialise an associative table in Lua?

Sarwagya
  • 166
  • 11
  • 1
    Note that `Y` is a closure and will be reinstantiated every time `X` is called, so no two `var1` tables will contain the same instance of `Y`. – Luatic May 19 '22 at 18:48