Re: Factories as script constructors.
Tom Nelson <[email protected]> Fri, 24 Feb 2012 07:38:56 -0800
| Newsgroups | gmane.comp.lang.lua.bind.user |
|---|---|
| Message-ID | <[email protected]> |
Here is what I have so far. I've included class.hpp and
detail/factory_ctor.hpp. I'm still on luabind 9.1 by the way. (Also my
plan is to get it working for 0 or 1 parameter before adding
PP_ITERATION back in. Take a look and see if anything jumps out at you.
The code is based on detail/constructor.hpp since that seemed to be the
closest to the functionality that I was trying to duplicate.
factory_ctor should create a structure with the function call operator
defined. The trick, I think, is how to get luabind to correctly
recognize the signature and build the call correctly.
I'm going to be looking at this more over the weekend.
Thanks again
Tom
On 02/23/2012 04:49 PM, Nigel Atkinson wrote:
> 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.
>>
>> Tom
------------------------------------------------------------------------------
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
luabindfactory.zip
(application/zip, 7.3 KB) - not displayed