C function return result (works on some objects, not others)

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

C function return result (works on some objects, not others)

Josh Green-3
Hey everybody, me again, this one is weird, and I'd appreciate your help
on it
I've been struggling with it for about a week now.

I have a few classes registered as follows:

class_<IResource>("Resource")
class_<Object,IResource>("Object")
class_<HeadsUpDisplayItem,Object>("HUDItem")
class_<GUIText,HeadsUpDisplayItem>("Text")
class_<GUIImage,HeadsUpDisplayItem>("Image")
class_<GUIButton,HeadsUpDisplayItem>("Button")
class_<GUIWindow,HeadsUpDisplayItem>("GUIWindow")

Now, I have a function that has been registered as follows:

class_<ResourceSystem>("ResourceSystem")
        .def("createInstance",&ResourceSystem::createInstance)

Now this function has the following signature:
IResource *ResourceSystem::createInstance(const char *name, unsigned int
= 0);

Basically what it does is I call: res = createInstance("Button",0) and
it should return a button object and store it in res.

Now this works great for all these classes EXCEPT, for GUIWindow.

The function DOES return the object as seen by setting breakpoints at
the end of the function, but the res object == nil after execution!

I have no idea why this is happening, any help would be greatly
appreciated
Any ideas of where I should be looking? Thanks

--Josh

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: C function return result (works on some objects, not others)

Josh Green-3
Ok so once again I've figured out this one myself, turns out I was
corrupting the lua stack when creating instances of GUIWindow

Thanks

--Josh

-----Original Message-----
From: [hidden email]
[mailto:[hidden email]] On Behalf Of Josh
Green
Sent: Saturday, 22 July 2006 10:46 PM
To: [hidden email]
Subject: [luabind] C function return result (works on some objects,not
others)


Hey everybody, me again, this one is weird, and I'd appreciate your help
on it I've been struggling with it for about a week now.

I have a few classes registered as follows:

class_<IResource>("Resource")
class_<Object,IResource>("Object")
class_<HeadsUpDisplayItem,Object>("HUDItem")
class_<GUIText,HeadsUpDisplayItem>("Text")
class_<GUIImage,HeadsUpDisplayItem>("Image")
class_<GUIButton,HeadsUpDisplayItem>("Button")
class_<GUIWindow,HeadsUpDisplayItem>("GUIWindow")

Now, I have a function that has been registered as follows:

class_<ResourceSystem>("ResourceSystem")
        .def("createInstance",&ResourceSystem::createInstance)

Now this function has the following signature:
IResource *ResourceSystem::createInstance(const char *name, unsigned int
= 0);

Basically what it does is I call: res = createInstance("Button",0) and
it should return a button object and store it in res.

Now this works great for all these classes EXCEPT, for GUIWindow.

The function DOES return the object as seen by setting breakpoints at
the end of the function, but the res object == nil after execution!

I have no idea why this is happening, any help would be greatly
appreciated Any ideas of where I should be looking? Thanks

--Josh

------------------------------------------------------------------------
-
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share
your opinions on IT & business topics through brief surveys -- and earn
cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDE
V
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: C function return result (works on some objects, not others)

Dmitriy Iassenev
In reply to this post by Josh Green-3
JG> class_<ResourceSystem>("ResourceSystem")
JG>         .def("createInstance",&ResourceSystem::createInstance)
not an answer on your question, but, probably, here is a memory leak:
you should register your function with the corresponding policy
(adopt policy), since instances of the classes you return to Lua never
will be collected by Lua garbage collector

.def("createInstance",&ResourceSystem::createInstance,adopt(result))

--
Best regards,
 Dmitriy                            mailto:[hidden email]


-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user