lua-users home
lua-l archive

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


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.

This information all looks to be readily available, so it's mostly just a matter of specifying the API. I haven't figured out whether one should make a proposal for such things, provide a proposal with an implementation, or just wait to see how Roberto responds. ;-)

(Slightly more difficult because I don't think the compiler tracks this would be tracking the number of return values. Again this could be useful for writing generic wrappers that tuned to their particular use cases.)

Mark