[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: RE: about the new version
- From: Luiz Henrique de Figueiredo <lhf@...>
- Date: Thu, 4 May 2000 17:03:53 -0300 (EST)
The problem here is that Lua does not have function declarations and so
there is no way to know that your `f' "requires" two arguments.
What happens with `tonumber' is that it is a builtin function, written in C,
and so is able to know that it requires exactly one argument, and give an
error message if not.
In other words, `tonumber' is being "nice" to the user.
C functions that receive a fixed number of arguments can do this type of
checking, but Lua functions can't.
So, C library writers have the choice to be "nice" to the user.
This is one reason that there is a difference between nil and LUA_NOOBJECT.
>From: "Luiz Carlos Silveira" <firstname.lastname@example.org>
>Following this concept, in the code below:
> return '1','2'
>'f' only receive one parameter, right?
>but shouldn?t this statement also work like the one before?
> tonumber(g(), nil)
>in which only one parameter should be received by the tonumber function?
>but it actually produces an error message:
>error: bad argument #2 to `tonumber' (number expected, got nil)
> function `tonumber' [C]
> main of string "tonumber(gsub('ab', 'a', ''), nil)"