lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]




On Mon, Oct 12, 2020 at 3:39 PM 孙世龙 sunshilong <sunshilong369@gmail.com> wrote:
Hi, list

How to comprehend "in Lua, all functions are anonymous. Like any other
value, they do not have names. " at a deeper level?


in Lua, functions are values.

so you can do this:

function aFn(a, b)
   return a + b
end

and do this

b = aFn

then

b(2,3) -- returns 5

and also

c = {b}
c[1](3,4) -- returns 7

or this

d = function()
       return aFn
    end ()
d(5,6) -- returns 11

Functions are just values, and a module, any Lua program, is just a function as well.

Hope that helps,
-Sam