Re: Factories as script constructors.

Ryan Pavlik <[email protected]> Fri, 24 Feb 2012 11:52:33 -0600
Newsgroups gmane.comp.lang.lua.bind.user
Message-ID <CABMFTE-5oTODZntgYvG4eSFoLpWJ2HigDCn95MnbS0u_aSgJFg@mail.gmail.com>
Seems like an useful addition and it sounds like you're on the right track
(at least, that's how I'd do it :D) Please feel free to fork on github to
keep track of your progress and share. Would be great to add a test at the
same time for that functionality.

Ryan

On Fri, Feb 24, 2012 at 9:38 AM, Tom Nelson <[email protected]> wrote:

> 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.&nbsp;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&nbsp;
>>> myF:doSomething()
>>>
>>> Has anyone else done something like this?&nbsp; 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.&nbsp;
>>>
>>> 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
>
>


-- 
Ryan Pavlik
HCI Graduate Student
Virtual Reality Applications Center
Iowa State University

[email protected]
http://academic.cleardefinition.com

------------------------------------------------------------------------------
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