[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: RE: Matching multibyte alphabetical characters with LPeG
- From: "Thijs Schreijer" <thijs@...>
- Date: Wed, 20 Jun 2012 16:49:34 +0200
> > and why cast it (incorrectly) as a lua_CFunction? Why not a boxed
> userdata?
>
> 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?
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?
Thijs