lua-users home
lua-l archive

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


Edgar Toernig wrote: 
> "Reuben Thomas,,,690081" wrote:
> > Indeed; this is one of the several reasons I think it would be good for even
> > the standard Lua libraries to be written using tolua (or a similar tool),
> > and for this practice to be encouraged for everyone.
> 
> I wouldn't go that far.  IMHO, the wish for a tool like tolua for simple
> tasks show that the API is too complex.

I'd say Lua has a wonderfully clean and simple API.  The epitome of "too
complex" is trying to access a Perl hash from a C function.


>   - when calling a C function the VM checks whether there are less
>     arguments on the stack then the closure wants (gettop<nargs).
>     In that case it pushes additional nils on the stack until there
>     are enough arguments (gettop==nargs).  If there are already
>     enough or even more arguments on the stack it does nothing.
>     Then the function is called.

I call lua_settop with the number of arguments that the function
expects.  This has two benefits: any omitted arguments are set to nil,
and you can count on arguments being in the correct place relative to
the top of the stack (no matter how many extra or too few the caller
provided) in case you want to pop, push or concat arguments and strings
into error messages.

- Peter