luabind 0.8.1 + lua 5.1.4: passed object pointers are userdata

View: New views
6 Messages — Rating Filter:   Alert me  

luabind 0.8.1 + lua 5.1.4: passed object pointers are userdata

by Dmitriy Mazovka :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello, I've faced the problem with passing registered class object's pointer to lua. It is not resolved to table somewhy. I've traced with a debugger and the algorithm seems went well - there were proper calls of lua_setmetatable and lua_settable.

The code is like in the basic example:

class TestClass
{
public:
   TestClass() {}
   void Test() { printf("Hello\n"); }
};


   TestClass obj;

   lua_State *state = lua_open();
   luabind::open(state);

   luabind::module(state)[
      luabind::class_<TestClass>("TestClass")
         .def(luabind::constructor<>())
         .def("Test", &TestClass::Test)
   ];

   if (luaL_loadstring(state, "function main(c) c:Test() end") != 0 ||
      lua_pcall(state, 0, LUA_MULTRET, 0) != 0)
   {
      ErrorHandle(state);
   }

   if (luaL_loadstring(state, "obj = TestClass(); main(obj)") != 0 ||
      lua_pcall(state, 0, LUA_MULTRET, 0) != 0)
   {
      ErrorHandle(state);
   }

   luabind::globals(state)["tmp"] = &obj;
   if (luaL_loadstring(state, "main(tmp)") != 0 ||
      lua_pcall(state, 0, LUA_MULTRET, 0) != 0)
   {
      ErrorHandle(state);
   }

   lua_close(state);



-----------------------
Output:
Hello
[string "function main(c) c:Test() end"]:1: attempt to index local 'c' (a userda
ta value)


Could you please give me some hint how to overcome this problem? :)
Regards,
_dm


------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
luabind-user mailing list
luabind-user@...
https://lists.sourceforge.net/lists/listinfo/luabind-user

Re: luabind 0.8.1 + lua 5.1.4: passed object pointers are userdata

by fuscated :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


On Sun, 18 Oct 2009 23:47:01 +0400
Dmitriy Mazovka <mazovka@...> wrote:
>    luabind::globals(state)["tmp"] = &obj;

Have you tried:
luabind::globals(state)["tmp"] = boost::ref(obj);

Best regards


------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
luabind-user mailing list
luabind-user@...
https://lists.sourceforge.net/lists/listinfo/luabind-user

Parent Message unknown Re: luabind 0.8.1 + lua 5.1.4: passed object pointers are userdata

by Dmitriy Mazovka :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Thank you, but it didn't help, i'm still receiving the same error


>
> On Sun, 18 Oct 2009 23:47:01 +0400
> Dmitriy Mazovka <mazovka@...> wrote:
> >    luabind::globals(state)["tmp"] = &obj;
>
> Have you tried:
> luabind::globals(state)["tmp"] = boost::ref(obj);
>
> Best regards
>
 

------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
luabind-user mailing list
luabind-user@...
https://lists.sourceforge.net/lists/listinfo/luabind-user

Re: luabind 0.8.1 + lua 5.1.4: passed object pointers are userdata

by Ilia Trendafilov :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Your code works for me (luabind 0.8.1, lua 5.1.4, VC2005/Win32,
luabind as dll). If you are on Windows, double-check
LUABIND_DYNAMIC_LINK macro consitency i.e. if you are building luabind
as dll, make sure that both the library and your program are compiled
with LUABIND_DYNAMIC_LINK defined; and if compiling luabind to static
library - make sure the macro is not defined for both luabind and your
program.

On Sun, Oct 18, 2009 at 10:29 PM, Dmitriy Mazovka <mazovka@...> wrote:

> Thank you, but it didn't help, i'm still receiving the same error
>
>
>>
>> On Sun, 18 Oct 2009 23:47:01 +0400
>> Dmitriy Mazovka <mazovka@...> wrote:
>> >    luabind::globals(state)["tmp"] = &obj;
>>
>> Have you tried:
>> luabind::globals(state)["tmp"] = boost::ref(obj);
>>
>> Best regards
>>
>
>
> ------------------------------------------------------------------------------
> Come build with us! The BlackBerry(R) Developer Conference in SF, CA
> is the only developer event you need to attend this year. Jumpstart your
> developing skills, take BlackBerry mobile applications to market and stay
> ahead of the curve. Join us from November 9 - 12, 2009. Register now!
> http://p.sf.net/sfu/devconference
> _______________________________________________
> luabind-user mailing list
> luabind-user@...
> https://lists.sourceforge.net/lists/listinfo/luabind-user
>

------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
luabind-user mailing list
luabind-user@...
https://lists.sourceforge.net/lists/listinfo/luabind-user

Re: luabind 0.8.1 + lua 5.1.4: passed object pointers are userdata

by Dmitriy Mazovka :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


-----Original Message-----
From: Ilia Trendafilov <itrend@...>
To: Dmitriy Mazovka <mazovka@...>, luabind-user@...
Date: Sun, 18 Oct 2009 22:39:13 +0200
Subject: Re: [luabind] luabind 0.8.1 + lua 5.1.4: passed object pointers are
userdata

> Your code works for me (luabind 0.8.1, lua 5.1.4, VC2005/Win32,
> luabind as dll). If you are on Windows, double-check
> LUABIND_DYNAMIC_LINK macro consitency i.e. if you are building luabind
> as dll, make sure that both the library and your program are compiled
> with LUABIND_DYNAMIC_LINK defined; and if compiling luabind to static
> library - make sure the macro is not defined for both luabind and your
> program.
>
> On Sun, Oct 18, 2009 at 10:29 PM, Dmitriy Mazovka <mazovka@...> wrote:
> > Thank you, but it didn't help, i'm still receiving the same error
> >
> >
> >>
> >> On Sun, 18 Oct 2009 23:47:01 +0400
> >> Dmitriy Mazovka <mazovka@...> wrote:
> >> > ? ?luabind::globals(state)["tmp"] = &obj;
> >>
> >> Have you tried:
> >> luabind::globals(state)["tmp"] = boost::ref(obj);
> >>
> >> Best regards
> >>
> >
> >
> > ------------------------------------------------------------------------------
> > Come build with us! The BlackBerry(R) Developer Conference in SF, CA
> > is the only developer event you need to attend this year. Jumpstart your
> > developing skills, take BlackBerry mobile applications to market and stay
> > ahead of the curve. Join us from November 9 - 12, 2009. Register now!
> > http://p.sf.net/sfu/devconference
> > _______________________________________________
> > luabind-user mailing list
> > luabind-user@...
> > https://lists.sourceforge.net/lists/listinfo/luabind-user
> >
>

------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
luabind-user mailing list
luabind-user@...
https://lists.sourceforge.net/lists/listinfo/luabind-user

Re: luabind 0.8.1 + lua 5.1.4: passed object pointers are userdata

by Dmitriy Mazovka :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Sorry for mistaken posting.

And thank you, everything works fine now!
I added LUABIND_DYNAMIC_LINK to the program project and everything is cool:). However it's weird, as previous version of luabind didn't need such tricks.

Thanks a lot.

-----Original Message-----
From: Ilia Trendafilov <itrend@...>
To: Dmitriy Mazovka <mazovka@...>, luabind-user@...
Date: Sun, 18 Oct 2009 22:39:13 +0200
Subject: Re: [luabind] luabind 0.8.1 + lua 5.1.4: passed object pointers are
userdata

> Your code works for me (luabind 0.8.1, lua 5.1.4, VC2005/Win32,
> luabind as dll). If you are on Windows, double-check
> LUABIND_DYNAMIC_LINK macro consitency i.e. if you are building luabind
> as dll, make sure that both the library and your program are compiled
> with LUABIND_DYNAMIC_LINK defined; and if compiling luabind to static
> library - make sure the macro is not defined for both luabind and your
> program.
>
> On Sun, Oct 18, 2009 at 10:29 PM, Dmitriy Mazovka <mazovka@...> wrote:
> > Thank you, but it didn't help, i'm still receiving the same error
> >
> >
> >>
> >> On Sun, 18 Oct 2009 23:47:01 +0400
> >> Dmitriy Mazovka <mazovka@...> wrote:
> >> > ? ?luabind::globals(state)["tmp"] = &obj;
> >>
> >> Have you tried:
> >> luabind::globals(state)["tmp"] = boost::ref(obj);
> >>
> >> Best regards
> >>
> >
> >
> > ------------------------------------------------------------------------------
> > Come build with us! The BlackBerry(R) Developer Conference in SF, CA
> > is the only developer event you need to attend this year. Jumpstart your
> > developing skills, take BlackBerry mobile applications to market and stay
> > ahead of the curve. Join us from November 9 - 12, 2009. Register now!
> > http://p.sf.net/sfu/devconference
> > _______________________________________________
> > luabind-user mailing list
> > luabind-user@...
> > https://lists.sourceforge.net/lists/listinfo/luabind-user
> >
>

------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
luabind-user mailing list
luabind-user@...
https://lists.sourceforge.net/lists/listinfo/luabind-user