Assigning the "this" pointer

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

Assigning the "this" pointer

Ben Ashley
Hi All,

Newbie Luabind user here!  I've been having great success implementing luabind in to my project, but have come across a snag.

I have the following code:

void LogManager::luaBindImpl() const
{
using namespace luabind;
lua_State* state(Supervisor::get<LuaManager>()->state());
// LogManager
module(state)
[
class_<LogManager>("LogManager")
.enum_("constants")
[
value("Info", 1)
,value("Warning", 2)
,value("Critical", 3)
,value("Debug", 4)
]
.def("log", &LogManager::log)
.def("registerSource", &LogManager::registerSource)
];

// Add to globals
globals(state)["LM"] = this;
}; // eo luaBindImpl

The problem is the line which sets the global "LM" to "this".  Whenever I call a function in my LUA script on "LM", I get the following error (reported in my log file):

00:00:01:0060- lua:Exception - No matching overload found, candidates:
void registerSource(LogManager&,std::string const&)

The lua code is this:


LM:registerSource("test");



Interestingly, when I do:

globals(state)["LM"] = new LogManager();


... everything works as intended.

Am I doing something obviously wrong?



Many thanks in advance!

------------------------------------------------------------------------------
vRanger cuts backup time in half-while increasing security.
With the market-leading solution for virtual backup and recovery,
you get blazing-fast, flexible, and affordable data protection.
Download your free trial now.
http://p.sf.net/sfu/quest-d2dcopy1
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: Assigning the "this" pointer

liam mail


On 28 May 2011 17:55, Ben Ashley <[hidden email]> wrote:
Hi All,

Newbie Luabind user here!  I've been having great success implementing luabind in to my project, but have come across a snag.

I have the following code:

void LogManager::luaBindImpl() const
{
using namespace luabind;
lua_State* state(Supervisor::get<LuaManager>()->state());
// LogManager
module(state)
[
class_<LogManager>("LogManager")
.enum_("constants")
[
value("Info", 1)
,value("Warning", 2)
,value("Critical", 3)
,value("Debug", 4)
]
.def("log", &LogManager::log)
.def("registerSource", &LogManager::registerSource)
];

// Add to globals
globals(state)["LM"] = this;
}; // eo luaBindImpl

The problem is the line which sets the global "LM" to "this".  Whenever I call a function in my LUA script on "LM", I get the following error (reported in my log file):

00:00:01:0060- lua:Exception - No matching overload found, candidates:
void registerSource(LogManager&,std::string const&)

The lua code is this:


LM:registerSource("test");



Interestingly, when I do:

globals(state)["LM"] = new LogManager();


... everything works as intended.

Am I doing something obviously wrong?



Many thanks in advance!

------------------------------------------------------------------------------
vRanger cuts backup time in half-while increasing security.
With the market-leading solution for virtual backup and recovery,
you get blazing-fast, flexible, and affordable data protection.
Download your free trial now.
http://p.sf.net/sfu/quest-d2dcopy1
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user


The function is constant which effects the type of the "this" pointer and therefore effects the function signature which Luabind is looking for, hence the error message.

For more detailed information see for example msdn docs[1]


------------------------------------------------------------------------------
vRanger cuts backup time in half-while increasing security.
With the market-leading solution for virtual backup and recovery,
you get blazing-fast, flexible, and affordable data protection.
Download your free trial now.
http://p.sf.net/sfu/quest-d2dcopy1
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: Assigning the "this" pointer

feng qiu-5
In reply to this post by Ben Ashley
try this one. It looks like your "LM" is a const pointer.
void registerSource(const LogManager*,std::string const&)

On 29 May 2011 00:55, Ben Ashley <[hidden email]> wrote:
Hi All,

Newbie Luabind user here!  I've been having great success implementing luabind in to my project, but have come across a snag.

I have the following code:

void LogManager::luaBindImpl() const
{
using namespace luabind;
lua_State* state(Supervisor::get<LuaManager>()->state());
// LogManager
module(state)
[
class_<LogManager>("LogManager")
.enum_("constants")
[
value("Info", 1)
,value("Warning", 2)
,value("Critical", 3)
,value("Debug", 4)
]
.def("log", &LogManager::log)
.def("registerSource", &LogManager::registerSource)
];

// Add to globals
globals(state)["LM"] = this;
}; // eo luaBindImpl

The problem is the line which sets the global "LM" to "this".  Whenever I call a function in my LUA script on "LM", I get the following error (reported in my log file):

00:00:01:0060- lua:Exception - No matching overload found, candidates:
void registerSource(LogManager&,std::string const&)

The lua code is this:


LM:registerSource("test");



Interestingly, when I do:

globals(state)["LM"] = new LogManager();


... everything works as intended.

Am I doing something obviously wrong?



Many thanks in advance!

------------------------------------------------------------------------------
vRanger cuts backup time in half-while increasing security.
With the market-leading solution for virtual backup and recovery,
you get blazing-fast, flexible, and affordable data protection.
Download your free trial now.
http://p.sf.net/sfu/quest-d2dcopy1
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user




--
Q..

------------------------------------------------------------------------------
vRanger cuts backup time in half-while increasing security.
With the market-leading solution for virtual backup and recovery,
you get blazing-fast, flexible, and affordable data protection.
Download your free trial now.
http://p.sf.net/sfu/quest-d2dcopy1
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user