lua-users home
lua-l archive

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


Hello,
is there any reasonable way to check, for a defined lua function, how
many arguments it expects and what are their names? And how many
arguments it can return?
I would expect this from debug.getinfo(f), but its not there.

For example:

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

and for debug.getinfo(sum) I could get:
{arguments:{"a","b"}, returns:1}

Or for more complicated example:
function sum(a,b)
  if not a or not b then return nil, "null arguments"
  return a+b
end

{arguments:{"a","b"}, returns:1,2} (means returns 1 or 2 arguments)

I know that the "returns" part is tricky, but the "arguments" part could
be doable, am I right?

Another proposal would be to have debug.setinfo(f, key, value), for example:
debug.setinfo(sum, "documentation", "Returns the sum of two arguments"),
so then following debug.getinfo() could return this field also. (it
could partially resolve "arguments"/"returns" proposal, if those could
not be set automatically).

This could help in generating documentation (for luadoc), code
completion within editors, creating webservices, and similar things.
What do you think?

Regards,
	miko