lua-users home
lua-l archive

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

> > It is not incorrect. ANSI C ensures that all pointers to functions are
> > compatible. That is, if A and B are pointers to functions, we can
> > convert from A to B and back to A without loss. Now that Lua 5.2 has
> > light C functions, this looks like an interesting technique to store
> > pointers to functions in Lua (as long as Lua code has no access to
> > them).
> > 
> > -- Roberto
> You refer specifically to 5.2. Does this mean it cannot be done reliably in
> 5.1 using lightuserdata for example?

Not in ANSI C.

> I did something slightly different; creating a userdata holding a structure
> containing only pointers to functions. Both libraries I used had the their
> own (but the exact same) definition of that structure. So lib A puts the
> userdata in the registry, lib B collects it there and calls the functions of
> A (stored as pointers in the struct). So far it works.
> But do I have trouble ahead?

That is safe.

-- Roberto