Exposing Abstract Interface with luabind ?

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Exposing Abstract Interface with luabind ?

Nicolas Goles-2
Hello!,

I'm want to expose an abstract interface with Luabind.
//Interface
class IAbstract
{
public:
    virtual ~IAbstract() {}
    virtual void method1(void) = 0;
    virtual void method2(void) = 0;
};

//Implementation A
class A : public IAbstract
{
    virtual void method1(void)
    {
         //Do some stuff
    }

    virtual void method2(void)
    {
        //Do other stuff
    }
};

//Implementation B
class B : public IAbstract
{
    virtual void method1(void)
    {
         //Do some stuff*
    }

    virtual void method2(void)
    {
        //Do other stuff*
    }
};

What's the best way to expose this IAbstract using luabind ( I'm not sure if I can expose abstract classes ) , in my code I have a manager/factory which returns a pointer to an IAbstract , under the hood it instantiates class A or B, and the idea is of course to only use IAbstract methods to interact with class A or B.

So to the question,

Is there a way to only expose the IAbstract (abstract class) so that in Lua I could do:
-- Lua code
abstract = manager:returnIAbstractReference()
abstract:method1()
abstract:method2()
Or I will have to expose ImplementationA, ImplementationB ... etc  ?

Thanks!
--
Nicolas Goles Domic
Founder & Lead Engineer
Gando Games

------------------------------------------------------------------------------
The ultimate all-in-one performance toolkit: Intel(R) Parallel Studio XE:
Pinpoint memory and threading errors before they happen.
Find and fix more than 250 security defects in the development cycle.
Locate bottlenecks in serial and parallel code that limit performance.
http://p.sf.net/sfu/intel-dev2devfeb
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: Exposing Abstract Interface with luabind ?

Nigel Atkinson-2
Short answer is, Yes.

Simply bind your abstract class as per normal classes and your factory
functions.  You will not need to bind your derived classes unless you
need to cast to them (which Luabind does automagically) in Lua.

Nigel

On Sun, 2011-02-20 at 12:41 -0300, Nicolas Goles wrote:

> Hello!,
>
> I'm want to expose an abstract interface with Luabind.
>         //Interface
>         class IAbstract
>         {
>         public:
>             virtual ~IAbstract() {}
>             virtual void method1(void) = 0;
>             virtual void method2(void) = 0;
>         };
>        
>         //Implementation A
>         class A : public IAbstract
>         {
>             virtual void method1(void)
>             {
>                  //Do some stuff
>             }
>        
>             virtual void method2(void)
>             {
>                 //Do other stuff
>             }
>         };
>        
>         //Implementation B
>         class B : public IAbstract
>         {
>             virtual void method1(void)
>             {
>                  //Do some stuff*
>             }
>        
>             virtual void method2(void)
>             {
>                 //Do other stuff*
>             }
>         };
>        
> What's the best way to expose this IAbstract using luabind ( I'm not
> sure if I can expose abstract classes ) , in my code I have a
> manager/factory which returns a pointer to an IAbstract , under the
> hood it instantiates class A or B, and the idea is of course to only
> use IAbstract methods to interact with class A or B.
>
> So to the question,
>
> Is there a way to only expose the IAbstract (abstract class) so that
> in Lua I could do:
>         -- Lua code
>         abstract = manager:returnIAbstractReference()
>         abstract:method1()
>         abstract:method2()
> Or I will have to expose ImplementationA, ImplementationB ... etc  ?
>
> Thanks!
> --
> Nicolas Goles Domic
> Founder & Lead Engineer
> Gando Games
> ------------------------------------------------------------------------------
> The ultimate all-in-one performance toolkit: Intel(R) Parallel Studio XE:
> Pinpoint memory and threading errors before they happen.
> Find and fix more than 250 security defects in the development cycle.
> Locate bottlenecks in serial and parallel code that limit performance.
> http://p.sf.net/sfu/intel-dev2devfeb
> _______________________________________________ luabind-user mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/luabind-user



------------------------------------------------------------------------------
The ultimate all-in-one performance toolkit: Intel(R) Parallel Studio XE:
Pinpoint memory and threading errors before they happen.
Find and fix more than 250 security defects in the development cycle.
Locate bottlenecks in serial and parallel code that limit performance.
http://p.sf.net/sfu/intel-dev2devfeb
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user