Binding static methods with luabind?

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

Binding static methods with luabind?

Nicolas Goles-2
Hello,

I have a Singleton Class in my application, it has a member method defined like:
	static LuaRegisterManager* getInstance();
I'm trying to register this class with Luabind, and expose some methods to Lua:
    //Register with luabind.
    luabind::module(L) 
    [
     luabind::class_<LuaRegisterManager>("LuaRegisterManager") //Register the class
     .def("execScript", (void(LuaRegisterManager::*)())&LuaRegisterManager::execScript) //method to execute a lua script
     .def("getInstance", &LuaRegisterManager::getInstance) //returns static singleton instance
     ];
The problem is that if I execute the following Lua script:
    LuaRegisterManager:getInstance()
I get :
	Error: no static 'getInstance' in class 'LuaRegisterManager'

So I guess I'm making an error and my static getInstance() method is not being registered with luabind correctly.

Help is welcome :)

--
Nicolas Goles Domic
Founder & Lead Programmer
Gando Games


------------------------------------------------------------------------------
Start uncovering the many advantages of virtual appliances
and start using them to simplify application deployment and
accelerate your shift to cloud computing.
http://p.sf.net/sfu/novell-sfdev2dev
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: Binding static methods with luabind?

Iliya Trendafilov
Hi,

That should do it, note the scope around the definition of getInstance

    luabind::module(L) 
    [
     luabind::class_<LuaRegisterManager>("LuaRegisterManager") //Register the class
     .def("execScript", (void(LuaRegisterManager::*)())&LuaRegisterManager::execScript) //method to execute a lua script
     .scope
      [
          def("getInstance", &LuaRegisterManager::getInstance) //returns static singleton instance
      ]
     ];

Invoke with LuaRegisterManager.getInstance() (i.e. dot instead of colon). A bit of explanation can be found here: http://www.rasterbar.com/products/luabind/docs.html#nested-scopes-and-static-functions

Hope that helps

On Wed, Sep 15, 2010 at 7:32 PM, Nicolas Goles <[hidden email]> wrote:
Hello,

I have a Singleton Class in my application, it has a member method defined like:
	static LuaRegisterManager* getInstance();
I'm trying to register this class with Luabind, and expose some methods to Lua:
    //Register with luabind.
    luabind::module(L) 
    [
     luabind::class_<LuaRegisterManager>("LuaRegisterManager") //Register the class
     .def("execScript", (void(LuaRegisterManager::*)())&LuaRegisterManager::execScript) //method to execute a lua script
     .def("getInstance", &LuaRegisterManager::getInstance) //returns static singleton instance
     ];
The problem is that if I execute the following Lua script:
    LuaRegisterManager:getInstance()
I get :
	Error: no static 'getInstance' in class 'LuaRegisterManager'

So I guess I'm making an error and my static getInstance() method is not being registered with luabind correctly.

Help is welcome :)

--
Nicolas Goles Domic
Founder & Lead Programmer
Gando Games


------------------------------------------------------------------------------
Start uncovering the many advantages of virtual appliances
and start using them to simplify application deployment and
accelerate your shift to cloud computing.
http://p.sf.net/sfu/novell-sfdev2dev
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user



------------------------------------------------------------------------------
Start uncovering the many advantages of virtual appliances
and start using them to simplify application deployment and
accelerate your shift to cloud computing.
http://p.sf.net/sfu/novell-sfdev2dev
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: Binding static methods with luabind?

Nicolas Goles-2
Great,

The .scope[] solved the problem ( now I have a different problem );

When I execute the Lua script I mentioned ( 1 line script )

	LuaRegisterManager:getInstance()

I get the following Error in my Console:

        Error: LuaRegisterManager* getInstance()

Before adding the .scope [] I was getting

	Error: no static 'getInstance' in class 'LuaRegisterManager'

So I guess it's finding the static method now , but there seems to be a
different error this time.

I am new to Lua/Luabind so help is really welcome.

Thanks!

--
Nicolas Goles Domic
Founder & Lead Programmer
Gando Games



Iliya Trendafilov wrote:
Hi,

That should do it, note the scope around the definition of getInstance

    luabind::module(L) 
    [
     luabind::class_<LuaRegisterManager>("LuaRegisterManager") //Register the class
     .def("execScript", (void(LuaRegisterManager::*)())&LuaRegisterManager::execScript) //method to execute a lua script
     .scope
      [
          def("getInstance", &LuaRegisterManager::getInstance) //returns static singleton instance
      ]
  
     ];

  
Invoke with LuaRegisterManager.getInstance() (i.e. dot instead of colon). A bit of explanation can be found here: http://www.rasterbar.com/products/luabind/docs.html#nested-scopes-and-static-functions

Hope that helps

On Wed, Sep 15, 2010 at 7:32 PM, Nicolas Goles <[hidden email]> wrote:
Hello,

I have a Singleton Class in my application, it has a member method defined like:
	static LuaRegisterManager* getInstance();
I'm trying to register this class with Luabind, and expose some methods to Lua:
    //Register with luabind.
    luabind::module(L) 
    [
     luabind::class_<LuaRegisterManager>("LuaRegisterManager") //Register the class
     .def("execScript", (void(LuaRegisterManager::*)())&LuaRegisterManager::execScript) //method to execute a lua script
     .def("getInstance", &LuaRegisterManager::getInstance) //returns static singleton instance
     ];
The problem is that if I execute the following Lua script:
    
    LuaRegisterManager:getInstance()
I get :
	Error: no static 'getInstance' in class 'LuaRegisterManager'

    

So I guess I'm making an error and my static getInstance() method is not being registered with luabind correctly.

Help is welcome :)

--
Nicolas Goles Domic
Founder & Lead Programmer
Gando Games


------------------------------------------------------------------------------
Start uncovering the many advantages of virtual appliances
and start using them to simplify application deployment and
accelerate your shift to cloud computing.
http://p.sf.net/sfu/novell-sfdev2dev
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user


------------------------------------------------------------------------------ Start uncovering the many advantages of virtual appliances and start using them to simplify application deployment and accelerate your shift to cloud computing. http://p.sf.net/sfu/novell-sfdev2dev

_______________________________________________ luabind-user mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/luabind-user

------------------------------------------------------------------------------
Start uncovering the many advantages of virtual appliances
and start using them to simplify application deployment and
accelerate your shift to cloud computing.
http://p.sf.net/sfu/novell-sfdev2dev
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: Binding static methods with luabind?

Nicolas Goles-2
In reply to this post by Iliya Trendafilov
Just saw your explanation about invoking with dot instead of : , read the docs and I get it now.

Thanks again!
--
Nicolas Goles Domic
Founder & Lead Programmer
Gando Games



Iliya Trendafilov wrote:
Hi,

That should do it, note the scope around the definition of getInstance

    luabind::module(L) 
    [
     luabind::class_<LuaRegisterManager>("LuaRegisterManager") //Register the class
     .def("execScript", (void(LuaRegisterManager::*)())&LuaRegisterManager::execScript) //method to execute a lua script
     .scope
      [
          def("getInstance", &LuaRegisterManager::getInstance) //returns static singleton instance
      ]
  
     ];

  
Invoke with LuaRegisterManager.getInstance() (i.e. dot instead of colon). A bit of explanation can be found here: http://www.rasterbar.com/products/luabind/docs.html#nested-scopes-and-static-functions

Hope that helps

On Wed, Sep 15, 2010 at 7:32 PM, Nicolas Goles <[hidden email]> wrote:
Hello,

I have a Singleton Class in my application, it has a member method defined like:
	static LuaRegisterManager* getInstance();
I'm trying to register this class with Luabind, and expose some methods to Lua:
    //Register with luabind.
    luabind::module(L) 
    [
     luabind::class_<LuaRegisterManager>("LuaRegisterManager") //Register the class
     .def("execScript", (void(LuaRegisterManager::*)())&LuaRegisterManager::execScript) //method to execute a lua script
     .def("getInstance", &LuaRegisterManager::getInstance) //returns static singleton instance
     ];
The problem is that if I execute the following Lua script:
    
    LuaRegisterManager:getInstance()
I get :
	Error: no static 'getInstance' in class 'LuaRegisterManager'

    

So I guess I'm making an error and my static getInstance() method is not being registered with luabind correctly.

Help is welcome :)

--
Nicolas Goles Domic
Founder & Lead Programmer
Gando Games


------------------------------------------------------------------------------
Start uncovering the many advantages of virtual appliances
and start using them to simplify application deployment and
accelerate your shift to cloud computing.
http://p.sf.net/sfu/novell-sfdev2dev
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user


------------------------------------------------------------------------------ Start uncovering the many advantages of virtual appliances and start using them to simplify application deployment and accelerate your shift to cloud computing. http://p.sf.net/sfu/novell-sfdev2dev

_______________________________________________ luabind-user mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/luabind-user

------------------------------------------------------------------------------
Start uncovering the many advantages of virtual appliances
and start using them to simplify application deployment and
accelerate your shift to cloud computing.
http://p.sf.net/sfu/novell-sfdev2dev
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: Binding static methods with luabind?

Nicolas Goles-2
In reply to this post by Nicolas Goles-2
Hello!,

Thanks for the wonderful explanation.

My binding ended  up like :

    //Register with luabind.
    luabind::module(L)
    [
     luabind::class_<LuaRegisterManager>("LuaRegisterManager")
     .def("execScript", (void(LuaRegisterManager::*)())&LuaRegisterManager::execScript)
     .scope
     [
      luabind::def("getInstance", &LuaRegisterManager::getInstance) //returns static singleton instance
      ]
     ];

It works great as you said, when performing the following Lua call:

LuaRegisterManager.getInstance()

However, what if I would like to call "execScript" (which I registered as a .def in my initial binding ? )

I thought it would be something like ( from Lua ) :

LuaRegisterManager.getInstance().execScript("script.lua")

But that returns the following error:

Error: No matching overload found, candidates:
void execScript(LuaRegisterManager&)


Thank you very much for all your help.

--
Nicolas Goles Domic
Founder & Lead Programmer
Gando Games



Iliya Trendafilov wrote:
Try LuaRegisterManager.getInstance()
Note there is a dot `.` between LuaRegisterManager and getInstance(), you seem to be using colon `:` instead.

In Lua the colon is just a syntactic sugar to mimic passing of this pointer in OO languages, the code `LuaRegisterManager:getInstance()` is equivalent to `LuaRegisterManager.getInstance(LuaRegisterManager)` which is not what you want.


On Wed, Sep 15, 2010 at 7:51 PM, Nicolas Goles <[hidden email]> wrote:
Great,

The .scope[] solved the problem ( now I have a different problem );

When I execute the Lua script I mentioned ( 1 line script )

	LuaRegisterManager:getInstance()

    

I get the following Error in my Console:

        Error: LuaRegisterManager* getInstance()

    

Before adding the .scope [] I was getting

	Error: no static 'getInstance' in class 'LuaRegisterManager'
So I guess it's finding the static method now , but there seems to be a different error this time.

I am new to Lua/Luabind so help is really welcome.

Thanks!


--
Nicolas Goles Domic
Founder & Lead Programmer
Gando Games



Iliya Trendafilov wrote:
Hi,

That should do it, note the scope around the definition of getInstance

    luabind::module(L) 
    [
     luabind::class_<LuaRegisterManager>("LuaRegisterManager") //Register the class
     .def("execScript", (void(LuaRegisterManager::*)())&LuaRegisterManager::execScript) //method to execute a lua script
     .scope
      [
          def("getInstance", &LuaRegisterManager::getInstance) //returns static singleton instance
      ]
  
     ];

  
Invoke with LuaRegisterManager.getInstance() (i.e. dot instead of colon). A bit of explanation can be found here: http://www.rasterbar.com/products/luabind/docs.html#nested-scopes-and-static-functions

Hope that helps

On Wed, Sep 15, 2010 at 7:32 PM, Nicolas Goles <[hidden email]> wrote:
Hello,

I have a Singleton Class in my application, it has a member method defined like:
	static LuaRegisterManager* getInstance();
I'm trying to register this class with Luabind, and expose some methods to Lua:
    //Register with luabind.
    luabind::module(L) 
    [
     luabind::class_<LuaRegisterManager>("LuaRegisterManager") //Register the class
     .def("execScript", (void(LuaRegisterManager::*)())&LuaRegisterManager::execScript) //method to execute a lua script
     .def("getInstance", &LuaRegisterManager::getInstance) //returns static singleton instance
     ];
The problem is that if I execute the following Lua script:
    
    LuaRegisterManager:getInstance()
I get :
	Error: no static 'getInstance' in class 'LuaRegisterManager'

    

So I guess I'm making an error and my static getInstance() method is not being registered with luabind correctly.

Help is welcome :)

--
Nicolas Goles Domic
Founder & Lead Programmer
Gando Games


------------------------------------------------------------------------------
Start uncovering the many advantages of virtual appliances
and start using them to simplify application deployment and
accelerate your shift to cloud computing.
http://p.sf.net/sfu/novell-sfdev2dev
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user


------------------------------------------------------------------------------ Start uncovering the many advantages of virtual appliances and start using them to simplify application deployment and accelerate your shift to cloud computing. http://p.sf.net/sfu/novell-sfdev2dev

_______________________________________________ luabind-user mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/luabind-user

------------------------------------------------------------------------------
Start uncovering the many advantages of virtual appliances
and start using them to simplify application deployment and
accelerate your shift to cloud computing.
http://p.sf.net/sfu/novell-sfdev2dev
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: Binding static methods with luabind?

Nigel Atkinson-2
Hi,

Just off the top of my head you want:

LuaRegisterManager.getInstance():execScript("script.lua")

Note the semi-colon rather than the period after getInstance().

Remember that

obj:func( p1, p2, etc )

is the same as

obj.func( obj, p1, p2, etc )

In the case above obj is the result of LuaRegisterManager.getInstance()

HTH

Nigel

On Wed, 2010-09-15 at 19:42 -0400, Nicolas Goles wrote:

> Hello!,
>
> Thanks for the wonderful explanation.
>
> My binding ended  up like :
>
>             //Register with luabind.
>             luabind::module(L)
>             [
>              luabind::class_<LuaRegisterManager>("LuaRegisterManager")
>              .def("execScript",
>         (void(LuaRegisterManager::*)())&LuaRegisterManager::execScript)
>              .scope
>              [
>               luabind::def("getInstance",
>         &LuaRegisterManager::getInstance) //returns static singleton
>         instance
>               ]
>              ];
> It works great as you said, when performing the following Lua call:
>
>         LuaRegisterManager.getInstance()
>
> However, what if I would like to call "execScript" (which I registered
> as a .def in my initial binding ? )
>
> I thought it would be something like ( from Lua ) :
>
>         LuaRegisterManager.getInstance().execScript("script.lua")
>
> But that returns the following error:
>
>         Error: No matching overload found, candidates:
>         void execScript(LuaRegisterManager&)
>        
>        
>
>
> Thank you very much for all your help.
>
>
> --
> Nicolas Goles Domic
> Founder & Lead Programmer
> Gando Games
>
>
>
>
> Iliya Trendafilov wrote:
> > Try LuaRegisterManager.getInstance()
> > Note there is a dot `.` between LuaRegisterManager and
> > getInstance(), you seem to be using colon `:` instead.
> >
> > In Lua the colon is just a syntactic sugar to mimic passing of this
> > pointer in OO languages, the code `LuaRegisterManager:getInstance()`
> > is equivalent to
> > `LuaRegisterManager.getInstance(LuaRegisterManager)` which is not
> > what you want.
> >
> >
> > On Wed, Sep 15, 2010 at 7:51 PM, Nicolas Goles
> > <[hidden email]> wrote:
> >         Great,
> >        
> >         The .scope[] solved the problem ( now I have a different
> >         problem );
> >        
> >         When I execute the Lua script I mentioned ( 1 line script )
> >        
> >         LuaRegisterManager:getInstance()
> >        
> >            
> >        
> >         I get the following Error in my Console:
> >        
> >        
> >                 Error: LuaRegisterManager* getInstance()
> >        
> >            
> >        
> >         Before adding the .scope [] I was getting
> >        
> >        
> >         Error: no static 'getInstance' in class 'LuaRegisterManager'
> >         So I guess it's finding the static method now , but there
> >         seems to be a different error this time.
> >        
> >         I am new to Lua/Luabind so help is really welcome.
> >        
> >         Thanks!
> >        
> >        
> >         --
> >         Nicolas Goles Domic
> >         Founder & Lead Programmer
> >         Gando Games
> >        
> >        
> >        
> >        
> >        
> >         Iliya Trendafilov wrote:
> >         > Hi,
> >         >
> >         > That should do it, note the scope around the definition of
> >         > getInstance
> >         >
> >         >     luabind::module(L)
> >         >     [
> >         >      luabind::class_<LuaRegisterManager>("LuaRegisterManager") //Register the class
> >         >      .def("execScript", (void(LuaRegisterManager::*)())&LuaRegisterManager::execScript) //method to execute a lua script
> >         >      .scope
> >         >       [
> >         >           def("getInstance", &LuaRegisterManager::getInstance) //returns static singleton instance
> >         >       ]
> >         >  
> >         >      ];
> >         >
> >         >  
> >         > Invoke with LuaRegisterManager.getInstance() (i.e. dot
> >         > instead of colon). A bit of explanation can be found here:
> >         > http://www.rasterbar.com/products/luabind/docs.html#nested-scopes-and-static-functions
> >         >
> >         > Hope that helps
> >         >
> >         > On Wed, Sep 15, 2010 at 7:32 PM, Nicolas Goles
> >         > <[hidden email]> wrote:
> >         >         Hello,
> >         >        
> >         >         I have a Singleton Class in my application, it has
> >         >         a member method defined like:
> >         >         static LuaRegisterManager* getInstance();
> >         >         I'm trying to register this class with Luabind,
> >         >         and expose some methods to Lua:
> >         >             //Register with luabind.
> >         >             luabind::module(L)
> >         >             [
> >         >              luabind::class_<LuaRegisterManager>("LuaRegisterManager") //Register the class
> >         >              .def("execScript", (void(LuaRegisterManager::*)())&LuaRegisterManager::execScript) //method to execute a lua script
> >         >              .def("getInstance", &LuaRegisterManager::getInstance) //returns static singleton instance
> >         >              ];
> >         >         The problem is that if I execute the following Lua script:
> >         >            
> >         >             LuaRegisterManager:getInstance()
> >         >         I get :
> >         >         Error: no static 'getInstance' in class 'LuaRegisterManager'
> >         >        
> >         >            
> >         >        
> >         >         So I guess I'm making an error and my static
> >         >         getInstance() method is not being registered with
> >         >         luabind correctly.
> >         >        
> >         >        
> >         >         Help is welcome :)
> >         >        
> >         >        
> >         >         --
> >         >         Nicolas Goles Domic
> >         >         Founder & Lead Programmer
> >         >         Gando Games
> >         >        
> >         >        
> >         >        
> >         >         ------------------------------------------------------------------------------
> >         >         Start uncovering the many advantages of virtual
> >         >         appliances
> >         >         and start using them to simplify application
> >         >         deployment and
> >         >         accelerate your shift to cloud computing.
> >         >         http://p.sf.net/sfu/novell-sfdev2dev
> >         >         _______________________________________________
> >         >         luabind-user mailing list
> >         >         [hidden email]
> >         >         https://lists.sourceforge.net/lists/listinfo/luabind-user
> >         >
> >         >
> >         >
> >         > __________________________________________________________
> >         > ------------------------------------------------------------------------------ Start uncovering the many advantages of virtual appliances and start using them to simplify application deployment and accelerate your shift to cloud computing. http://p.sf.net/sfu/novell-sfdev2dev
> >         >
> >         > __________________________________________________________
> >         >
> >         > _______________________________________________
> >         > luabind-user mailing list
> >         > [hidden email]
> >         > https://lists.sourceforge.net/lists/listinfo/luabind-user
> >         >  
> ------------------------------------------------------------------------------
> Start uncovering the many advantages of virtual appliances
> and start using them to simplify application deployment and
> accelerate your shift to cloud computing.
> http://p.sf.net/sfu/novell-sfdev2dev
> _______________________________________________ luabind-user mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/luabind-user



------------------------------------------------------------------------------
Start uncovering the many advantages of virtual appliances
and start using them to simplify application deployment and
accelerate your shift to cloud computing.
http://p.sf.net/sfu/novell-sfdev2dev
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: Binding static methods with luabind?

Nicolas Goles-2
Thanks for your answer,

However I've already tried that from Lua ( LuaRegisterManager.getInstance():execScript("script.lua") ) , without luck,

I'm getting the following error:

Error: No matching overload found, candidates:
void execScript(LuaRegisterManager&)


my exectScript method looks like this in C++:
void LuaRegisterManager::execScript(const char *script)
When I perform the binding of my LuaRegisterManager, I do:
.def("execScript",(void(LuaRegisterManager::*)())&LuaRegisterManager::execScript)
Maybe the problem is in the .def ?

Thanks again!
--
Nicolas Goles Domic
Founder & Lead Programmer
Gando Games

Nigel Atkinson wrote:
Hi,

Just off the top of my head you want:

LuaRegisterManager.getInstance():execScript("script.lua")

Note the semi-colon rather than the period after getInstance().

Remember that

obj:func( p1, p2, etc )

is the same as

obj.func( obj, p1, p2, etc )

In the case above obj is the result of LuaRegisterManager.getInstance()

HTH

Nigel

On Wed, 2010-09-15 at 19:42 -0400, Nicolas Goles wrote:
  
Hello!, 

Thanks for the wonderful explanation.

My binding ended  up like :

            //Register with luabind.
            luabind::module(L) 
            [
             luabind::class_<LuaRegisterManager>("LuaRegisterManager")
             .def("execScript",
        (void(LuaRegisterManager::*)())&LuaRegisterManager::execScript)
             .scope
             [
              luabind::def("getInstance",
        &LuaRegisterManager::getInstance) //returns static singleton
        instance
              ]
             ];
It works great as you said, when performing the following Lua call:

        LuaRegisterManager.getInstance()

However, what if I would like to call "execScript" (which I registered
as a .def in my initial binding ? )

I thought it would be something like ( from Lua ) :

        LuaRegisterManager.getInstance().execScript("script.lua")

But that returns the following error:

        Error: No matching overload found, candidates:
        void execScript(LuaRegisterManager&)
        
        


Thank you very much for all your help.


-- 
Nicolas Goles Domic
Founder & Lead Programmer
Gando Games




Iliya Trendafilov wrote: 
    
Try LuaRegisterManager.getInstance()
Note there is a dot `.` between LuaRegisterManager and
getInstance(), you seem to be using colon `:` instead. 

In Lua the colon is just a syntactic sugar to mimic passing of this
pointer in OO languages, the code `LuaRegisterManager:getInstance()`
is equivalent to
`LuaRegisterManager.getInstance(LuaRegisterManager)` which is not
what you want.


On Wed, Sep 15, 2010 at 7:51 PM, Nicolas Goles
[hidden email] wrote:
        Great, 
        
        The .scope[] solved the problem ( now I have a different
        problem );
        
        When I execute the Lua script I mentioned ( 1 line script )
        
        	LuaRegisterManager:getInstance()
        
            
        
        I get the following Error in my Console:
        
        
                Error: LuaRegisterManager* getInstance()
        
            
        
        Before adding the .scope [] I was getting 
        
        
        	Error: no static 'getInstance' in class 'LuaRegisterManager'
        So I guess it's finding the static method now , but there
        seems to be a different error this time.
        
        I am new to Lua/Luabind so help is really welcome.
        
        Thanks! 
        
        
        -- 
        Nicolas Goles Domic
        Founder & Lead Programmer
        Gando Games
        
        
        
        
        
        Iliya Trendafilov wrote: 
        > Hi,
        > 
        > That should do it, note the scope around the definition of
        > getInstance
        > 
        >     luabind::module(L) 
        >     [
        >      luabind::class_<LuaRegisterManager>("LuaRegisterManager") //Register the class
        >      .def("execScript", (void(LuaRegisterManager::*)())&LuaRegisterManager::execScript) //method to execute a lua script
        >      .scope
        >       [
        >           def("getInstance", &LuaRegisterManager::getInstance) //returns static singleton instance
        >       ]
        >   
        >      ];
        > 
        >   
        > Invoke with LuaRegisterManager.getInstance() (i.e. dot
        > instead of colon). A bit of explanation can be found here:
        > http://www.rasterbar.com/products/luabind/docs.html#nested-scopes-and-static-functions
        > 
        > Hope that helps
        > 
        > On Wed, Sep 15, 2010 at 7:32 PM, Nicolas Goles
        > [hidden email] wrote:
        >         Hello,
        >         
        >         I have a Singleton Class in my application, it has
        >         a member method defined like:
        >         	static LuaRegisterManager* getInstance();
        >         I'm trying to register this class with Luabind,
        >         and expose some methods to Lua: 
        >             //Register with luabind.
        >             luabind::module(L) 
        >             [
        >              luabind::class_<LuaRegisterManager>("LuaRegisterManager") //Register the class
        >              .def("execScript", (void(LuaRegisterManager::*)())&LuaRegisterManager::execScript) //method to execute a lua script
        >              .def("getInstance", &LuaRegisterManager::getInstance) //returns static singleton instance
        >              ];
        >         The problem is that if I execute the following Lua script:
        >             
        >             LuaRegisterManager:getInstance()
        >         I get :
        >         	Error: no static 'getInstance' in class 'LuaRegisterManager'
        >         
        >             
        >         
        >         So I guess I'm making an error and my static
        >         getInstance() method is not being registered with
        >         luabind correctly.
        >         
        >         
        >         Help is welcome :)
        >         
        >         
        >         -- 
        >         Nicolas Goles Domic
        >         Founder & Lead Programmer
        >         Gando Games
        >         
        >         
        >         
        >         ------------------------------------------------------------------------------
        >         Start uncovering the many advantages of virtual
        >         appliances
        >         and start using them to simplify application
        >         deployment and
        >         accelerate your shift to cloud computing.
        >         http://p.sf.net/sfu/novell-sfdev2dev
        >         _______________________________________________
        >         luabind-user mailing list
        >         [hidden email]
        >         https://lists.sourceforge.net/lists/listinfo/luabind-user
        > 
        > 
        > 
        > __________________________________________________________
        > ------------------------------------------------------------------------------ Start uncovering the many advantages of virtual appliances and start using them to simplify application deployment and accelerate your shift to cloud computing. http://p.sf.net/sfu/novell-sfdev2dev
        > 
        > __________________________________________________________
        > 
        > _______________________________________________
        > luabind-user mailing list
        > [hidden email]
        > https://lists.sourceforge.net/lists/listinfo/luabind-user
        >   
      
------------------------------------------------------------------------------
Start uncovering the many advantages of virtual appliances
and start using them to simplify application deployment and
accelerate your shift to cloud computing.
http://p.sf.net/sfu/novell-sfdev2dev
_______________________________________________ luabind-user mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/luabind-user
    



------------------------------------------------------------------------------
Start uncovering the many advantages of virtual appliances
and start using them to simplify application deployment and
accelerate your shift to cloud computing.
http://p.sf.net/sfu/novell-sfdev2dev
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
  

------------------------------------------------------------------------------
Start uncovering the many advantages of virtual appliances
and start using them to simplify application deployment and
accelerate your shift to cloud computing.
http://p.sf.net/sfu/novell-sfdev2dev
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: Binding static methods with luabind?

Nicolas Goles-2
In reply to this post by Nigel Atkinson-2
Ok, I fixed the problem

I don't know why I was doing such a complex binding when I wasn't using overloaded member functions.

The following works

    LuaRegisterManager.getInstance():execScript('hola.lua')

When using this typical binding

     .def("execScript", &LuaRegisterManager::execScript)

Thank you all. :)
--
Nicolas Goles Domic
Founder & Lead Programmer
Gando Games



Nigel Atkinson wrote:
Hi,

Just off the top of my head you want:

LuaRegisterManager.getInstance():execScript("script.lua")

Note the semi-colon rather than the period after getInstance().

Remember that

obj:func( p1, p2, etc )

is the same as

obj.func( obj, p1, p2, etc )

In the case above obj is the result of LuaRegisterManager.getInstance()

HTH

Nigel

On Wed, 2010-09-15 at 19:42 -0400, Nicolas Goles wrote:
  
Hello!, 

Thanks for the wonderful explanation.

My binding ended  up like :

            //Register with luabind.
            luabind::module(L) 
            [
             luabind::class_<LuaRegisterManager>("LuaRegisterManager")
             .def("execScript",
        (void(LuaRegisterManager::*)())&LuaRegisterManager::execScript)
             .scope
             [
              luabind::def("getInstance",
        &LuaRegisterManager::getInstance) //returns static singleton
        instance
              ]
             ];
It works great as you said, when performing the following Lua call:

        LuaRegisterManager.getInstance()

However, what if I would like to call "execScript" (which I registered
as a .def in my initial binding ? )

I thought it would be something like ( from Lua ) :

        LuaRegisterManager.getInstance().execScript("script.lua")

But that returns the following error:

        Error: No matching overload found, candidates:
        void execScript(LuaRegisterManager&)
        
        


Thank you very much for all your help.


-- 
Nicolas Goles Domic
Founder & Lead Programmer
Gando Games




Iliya Trendafilov wrote: 
    
Try LuaRegisterManager.getInstance()
Note there is a dot `.` between LuaRegisterManager and
getInstance(), you seem to be using colon `:` instead. 

In Lua the colon is just a syntactic sugar to mimic passing of this
pointer in OO languages, the code `LuaRegisterManager:getInstance()`
is equivalent to
`LuaRegisterManager.getInstance(LuaRegisterManager)` which is not
what you want.


On Wed, Sep 15, 2010 at 7:51 PM, Nicolas Goles
[hidden email] wrote:
        Great, 
        
        The .scope[] solved the problem ( now I have a different
        problem );
        
        When I execute the Lua script I mentioned ( 1 line script )
        
        	LuaRegisterManager:getInstance()
        
            
        
        I get the following Error in my Console:
        
        
                Error: LuaRegisterManager* getInstance()
        
            
        
        Before adding the .scope [] I was getting 
        
        
        	Error: no static 'getInstance' in class 'LuaRegisterManager'
        So I guess it's finding the static method now , but there
        seems to be a different error this time.
        
        I am new to Lua/Luabind so help is really welcome.
        
        Thanks! 
        
        
        -- 
        Nicolas Goles Domic
        Founder & Lead Programmer
        Gando Games
        
        
        
        
        
        Iliya Trendafilov wrote: 
        > Hi,
        > 
        > That should do it, note the scope around the definition of
        > getInstance
        > 
        >     luabind::module(L) 
        >     [
        >      luabind::class_<LuaRegisterManager>("LuaRegisterManager") //Register the class
        >      .def("execScript", (void(LuaRegisterManager::*)())&LuaRegisterManager::execScript) //method to execute a lua script
        >      .scope
        >       [
        >           def("getInstance", &LuaRegisterManager::getInstance) //returns static singleton instance
        >       ]
        >   
        >      ];
        > 
        >   
        > Invoke with LuaRegisterManager.getInstance() (i.e. dot
        > instead of colon). A bit of explanation can be found here:
        > http://www.rasterbar.com/products/luabind/docs.html#nested-scopes-and-static-functions
        > 
        > Hope that helps
        > 
        > On Wed, Sep 15, 2010 at 7:32 PM, Nicolas Goles
        > [hidden email] wrote:
        >         Hello,
        >         
        >         I have a Singleton Class in my application, it has
        >         a member method defined like:
        >         	static LuaRegisterManager* getInstance();
        >         I'm trying to register this class with Luabind,
        >         and expose some methods to Lua: 
        >             //Register with luabind.
        >             luabind::module(L) 
        >             [
        >              luabind::class_<LuaRegisterManager>("LuaRegisterManager") //Register the class
        >              .def("execScript", (void(LuaRegisterManager::*)())&LuaRegisterManager::execScript) //method to execute a lua script
        >              .def("getInstance", &LuaRegisterManager::getInstance) //returns static singleton instance
        >              ];
        >         The problem is that if I execute the following Lua script:
        >             
        >             LuaRegisterManager:getInstance()
        >         I get :
        >         	Error: no static 'getInstance' in class 'LuaRegisterManager'
        >         
        >             
        >         
        >         So I guess I'm making an error and my static
        >         getInstance() method is not being registered with
        >         luabind correctly.
        >         
        >         
        >         Help is welcome :)
        >         
        >         
        >         -- 
        >         Nicolas Goles Domic
        >         Founder & Lead Programmer
        >         Gando Games
        >         
        >         
        >         
        >         ------------------------------------------------------------------------------
        >         Start uncovering the many advantages of virtual
        >         appliances
        >         and start using them to simplify application
        >         deployment and
        >         accelerate your shift to cloud computing.
        >         http://p.sf.net/sfu/novell-sfdev2dev
        >         _______________________________________________
        >         luabind-user mailing list
        >         [hidden email]
        >         https://lists.sourceforge.net/lists/listinfo/luabind-user
        > 
        > 
        > 
        > __________________________________________________________
        > ------------------------------------------------------------------------------ Start uncovering the many advantages of virtual appliances and start using them to simplify application deployment and accelerate your shift to cloud computing. http://p.sf.net/sfu/novell-sfdev2dev
        > 
        > __________________________________________________________
        > 
        > _______________________________________________
        > luabind-user mailing list
        > [hidden email]
        > https://lists.sourceforge.net/lists/listinfo/luabind-user
        >   
      
------------------------------------------------------------------------------
Start uncovering the many advantages of virtual appliances
and start using them to simplify application deployment and
accelerate your shift to cloud computing.
http://p.sf.net/sfu/novell-sfdev2dev
_______________________________________________ luabind-user mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/luabind-user
    



------------------------------------------------------------------------------
Start uncovering the many advantages of virtual appliances
and start using them to simplify application deployment and
accelerate your shift to cloud computing.
http://p.sf.net/sfu/novell-sfdev2dev
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
  

------------------------------------------------------------------------------
Start uncovering the many advantages of virtual appliances
and start using them to simplify application deployment and
accelerate your shift to cloud computing.
http://p.sf.net/sfu/novell-sfdev2dev
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user