Re: Factories as script constructors.
Nigel Atkinson <[email protected]> Fri, 24 Feb 2012 11:49:27 +1100
| Newsgroups | gmane.comp.lang.lua.bind.user |
|---|---|
| Message-ID | <[email protected]> |
This looks interesting, and in my opinion would make a useful addition
to the library. Unfortunately I'm probably not better than you at
template meta programming, but I'm happy to take a look and see if
anything "jumps out".
I have a related yet different technique for singleton classes. In
this case I want to make it explicit in the Lua code that it is a
singleton. Fortunately vanilla Luabind can be used.
class_< SomeManager>( "SomeManager" )
.scope
[
.def( "getSingleton", &SomeManager::getSingleton )
]
.def( "func", &SomeManager::memberfunc )
mgr = SomeManager.getSingleton()
mgr:func()
Nigel
On 24/02/2012, at 9:57 AM, Thomas Nelson wrote:
>
> 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
------------------------------------------------------------------------------
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/