Lua `local a = {b=func1}`

62 views Asked by At

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!

1

There are 1 answers

1
Sarwagya On

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?