lua-users home
lua-l archive

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


On 07/04/14 17:37, jesus manuel Castillo blanco wrote:
> I have a subjection that you may want to consider, you have chosen to use callbacks function in the C style because you needed to allow multiple callbacks to be allow and C++ make this difficult,
Not so difficult that every man, dog and cat seems to make a C++
wrapper, and there are many libraries which can do this for you.[1]

 so I thought you make want to use the method on the link bellow that I
was discussing with some guys of about passing C++ methods pointer. I
realized that it may be a bit risky but so is passing C callbacks with
the advantage that now I don't have to create a function that some how
has access to a instance of a class. I think this would make LUA easier
to use.
> 
> http://stackoverflow.com/questions/20359668/is-it-safe-to-calling-a-member-function-not-defined-on-the-base-class-from-of-a
> 

You may want to take a look at squirrel[2] which IIRC started out as a
fork of Lua which has C++ functions as part of the core. Alternatively,
consider one of a number of GPG articles, some even written by the Lua
authors, which enable C++ class and function binding.

Lua is a C library which can be compiled as C++ yet this just enables
C++ exceptions. To enable your proposal Lua would need to become a C++
library which with a C++ type system. Consider the case of two classes
Foo and Bar, which are not related, with Bar exposing a function "func".
What would happen if you called "func" passing an instance of Foo? The
other, and worst of all, proposal is as the SO thread would seem to
indicate; the god pattern[3]. Even when using the god pattern it would
still not prevent the above afore mentioned case.

[1] http://lua-users.org/wiki/BindingCodeToLua
[2] http://www.squirrel-lang.org/
[3] The god pattern is where all objects derive from a specific base class.

-- 
Liam

Attachment: signature.asc
Description: OpenPGP digital signature