lua-users home
lua-l archive

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


I have a feeling closures for C functions aren't used much so no one has
complained about this yet...

If I understand the API correctly, there is a problem with the
pushcclosure/tocfunction set in that the upvalue data provided with
pushcclosure cannot be read back.  It's like being able to set the state of
something but not read it back, which generally indicates an API weakness.

In the current API what is tocfunction useful for?  You cannot use it to
call the lua_CFunction directly because possibly upvalues would have to be
placed on the stack first.  For the same reason you cannot use it to get a
lua_CFunction and then push it onto the stack again.  Perhaps this function
made sense before upvalues came along, but it no longer seems complete.

To get the missing information, maybe a function like this could be added:

    /* push upvalues for function at given index into the stack, returns
number of upvalues */
    int lua_getcclosure( lua_State*, int index );

Using this function along with lua_tocfunction, you could then access all
the information that was originally provided with lua_pushcclosure.

-John