lua-users home
lua-l archive

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

> I had a look at liolib.c but I did't understand exactly what I should 
> do. It seem that the standard Lua I/O function uses an additional 
> parameter (for examples, io_flush() seem to need 2 parameters). 

The "additional parameter" in these functions are upvalues; they are
registered with the functions (see lua_iolibopen), so that whenever Lua
calls these functions it adds these additional parameters automatically
(in front of the `real' parameters from the call).

This upvalue is used to carry extra information for these functions (for
instance, the tag for file handles).

If your function is being registered without upvalues, then the
«(FILE *) lua_getuserdata(lua_getparam(1))» should work without problems.
If your function is registered with upvalues, then you must call
lua_getparam(2) (the first parameter is the upvalue).

(BTW, did you check the result of openfile?)

> Moreover, all liolib.c struct and functions are static and I guess that 
> nobody else should call them directly.

They are static only because they are no part of the official API. If you 
really need them (and if you know what you are doing), there is no problem 
in turning them public. 

-- Roberto