lua-users home
lua-l archive

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


On Fri, Jul 2, 2010 at 3:45 PM, Mark Hamburg <mark@grubmah.com> wrote:
> Since LuaJIT doesn't do much to optimize ... and I suspect (but haven't confirmed) that it's also less performant for the main Lua distribution, it would be useful to have introspection support for finding out how many parameters a function takes plus whether or not it takes varargs. This could then be used in code generation logic to replace ... with an appropriate number of explicitly named parameters. For example, the following:
>
>        function concat( f, g )
>                return function( ... ) return f( g( ... ) ) end
>        end
>
> Can probably be more efficiently written in the case where g takes only one parameter as:
>
>        function concat1( f, g )
>                return function( x ) return f( g( x ) ) end
>        end
>
> With appropriate introspection we could detect this in the implementation of concat.
In 5.2-work3, the (lua_|debug.)getinfo function has also had an
upgrade; there is a new "t" option which fills in a field called
istailcall, and the existing "u" option now also fills in two fields
called nparams and isvararg. I believe these last two fields are what
you're asking for.