[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: RE: Retrieving the list of the functions declared in a script file
- From: "Virgil Smith" <Virgil@...>
- Date: Mon, 7 Jun 2004 10:17:27 -0500
The authors or those who have studied and/or modified the source may be able
to answer your exact question, but I will go ahead and answer the
fundamental Lua usage question this suggests (to me).
When calling a Lua function you will not get any type of error if you supply
the wrong number of parameters. Lua will adjust the number of supplied
parameters to the number of arguments the function accepts. Specifically,
if you supply too many parameters the "extras" will be dropped, and if you
supply too few parameters the "extra arguments" will contain nil when the
function body is executed. Also, Lua functions may have a variable number
of arguments. Such a function will have all appropriate parameters wrapped
up into an "arg" table. See the reference manual for more information.
It is fairly simple for the code inside a function to "reinterpret" its
arguments based on the number of parameters it received (or their type).
For instance a function may accept one "canonical" form of some item as a
parameter, or some list of values that can be used to derive the "canonical"
form. However, I personally know of no way to perform this check from
outside the function (though I can understand why in a user scripted
environment you might want to).
Personally, I don't think that the "function overloading" concept is worth
this effort. If there are multiple ways to implement a script function,
then I suggest expressing each with a different name and stating the
precedence/preference the engine will give to each.
-----Original Message-----
From: lua-bounces@bazar2.conectiva.com.br
[mailto:lua-bounces@bazar2.conectiva.com.br]On Behalf Of Francesco
Sent: Monday, June 07, 2004 4:38 AM
To: Lua list
Subject: Re: Retrieving the list of the functions declared in a script
file
Thanks Virgil,
> Did you run the loaded script before exploring LUA_GLOBALSINDEX?
no; you were right; I couldn't find the functions declared in the script
file in LUA_GLOBALSINDEX because I didn't run the script
yet.
I changed my test program and now everything works fine; still I have one
problem.....
- is there a way to know how many arguments a scripted function takes ?
does lua store this info somewhere or
it just try to match the given arguments to the function's arguments
directly when running the function (thus in an hardcoded way) ?
Thanks again,
Francesco