lua-users home
lua-l archive

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


Am 26.05.2014 20:16 schröbte Rena:
On 2014-05-25 9:25 PM, "Philipp Janda" <siffiejoe@gmx.net> wrote:
Traditionally[1], the function is called `fn` and uses P1-P9 for
parameters and L1-L9 for upvalues.

   [1]: http://lua-users.org/wiki/ShortAnonymousFunctions


That does look more elegant than doing string substitution, though I wonder
about the overhead of having 9 parameters.


The bytecode doesn't change as long as you don't use the parameters, so I guess there will be little runtime overhead. The Proto objects increase by 16 bytes per parameter (on x86_64; probably 12 bytes on 32 bit machines). On the plus side you don't create a table on every call (but you have to be careful with your caching or you will create a new closure, even if you don't use the local variables L1-L9) ...

Philipp