Factories as script constructors.
Thomas Nelson <[email protected]> Thu, 23 Feb 2012 14:57:31 PST
| Newsgroups | gmane.comp.lang.lua.bind.user |
|---|---|
| Message-ID | <[email protected]> |
I have a C++ class that I want to export to Lua. This class requires a factory method to construct and I would like to hide this little detail from the script side of things.
If my class looks like this:
class Foo
{
public:
static boost::shared_ptr<Foo> factoryFoo( int N );
void doSomething( );
protected:
Foo() ;
};
module(L)
[
class_<Foo, boost::shared_ptr<Foo> >("LuaFoo")
.factory(&Foo::factoryFoo)
.def("doSomething", &Foo::doSomething)
];
From the script I would be able to do the following:
myF = LuaFoo( 5 ) -- Actually calls the static method Foo::factoryFoo
myF:doSomething()
Has anyone else done something like this? I’ve gotten quite a ways by cloning and mutating the constructor.hpp implementation and adapting it to call a static member but I’m now getting lost in template expansion hell.
I seem to be encountering two problems:
1) Figuring out the Signature deduction templates and making my static function “look” like a constructor.
2) Determining the boost::shared_ptr<foo> when I’m deep inside the factory wrapper.
If anybody has some experience in these areas it would be great.
TomN
------------------------------------------------------------------------------
Virtualization & Cloud Management Using Capacity Planning
Cloud computing makes use of virtualization - but cloud computing
also focuses on allowing computing to be delivered as a service.
http://www.accelacomm.com/jaw/sfnl/114/51521223/
_______________________________________________
luabind-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/luabind-user