lua-users home
lua-l archive

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

function in C can also be anonymous, or have several names. The association is in the exported symbols for the linker, inside a dictionary that maps symbols to anonymous function entry points (plus some metadata allowing to load its code either at link time or at runtime; the names used by the linker are not the same as those exposed in the source code, even without using any macrosubstitution, because the compiler may "decorate" it, for example to add a signature for its datatype or its calling convention).

But at runtime (after the code is loaded) these functions are also anonymous, but they may eventually be exposed in a reflection API or a debugger (if debugging info was generated and not stripped from the binary), but if you've traced C programs, there are frequent cases where no symbol is even generated and all you get is a base symbol plus some offset.... Finally the initial symbols used at link time is not necessarily the same as the name that may be exported (or it may not be exported at all, especially "static" functions, accessible only inside the current module, or by an anonymous function pointer passed from one module to another, for example for callbacks).

Le mar. 13 oct. 2020 à 03:39, 孙世龙 sunshilong <> a écrit :
Hi, list

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

I know that the named function syntax function add(a,b) return a+b end
is actually a syntactic sugar for add = function(a,b) return a+b end.
And I  understand that you can specify the sorting order for
table.sort() by anonymous function.

Why does Lua prefer to anonymous functions, unlike the functions in C?
What're the advantages comparing with providing non-anonymous function syntax?

Thank you for your attention to my question.
Looking forward to hearing from you.

Best regards