Re: luabind and std::multimap

Tom Nelson <[email protected]> Tue, 21 Feb 2012 06:41:40 -0800
Newsgroups gmane.comp.lang.lua.bind.user
Message-ID <[email protected]>
Sorry it took me so long to get this too you. You can use these as 
examples, I recommend against using std::list and std::set in their 
current forms (the containers do not support random access so the 
implementations are very inefficient, you may need to solve this problem 
to get this solution to work.)

To get the effect you seem to be looking for first add a new set of 
templates to support ranges of iterators in stl_container_converter.hpp 
like so:

template <class I>
struct default_converter< const std::pair< I, I > *>

And have that build a new detail::stl_adapter< std::pair < > > in its 
apply method. In stl_container_adapter.hpp implement a new 
specialization for iterating across (pair.right, pair.left].

Then add a new partial specialization for std::multimap (converter and 
adapter) you'll need to override, at the very least, the __index and 
__next methods. You may need to store some sort of state information on 
metatable as well.

Good luck.

On 02/14/2012 07:43 AM, Tom Nelson wrote:
> I did some work a while ago with direct access to stl containers from
> lua, I'll see if I can dig up the code this evening.
>
> This is a pre-coffee suggestion, but rather than exporting the pairs you
> may want to consider writing a set of adapters and including them in
> luabind itself. The one for the multimap itself would present itself as
> a table. The keys into the table could then be presented as tables
> themselves which iterate across std::pair<  std::lower_bound,
> std::upper_bound>
>
> On 02/14/2012 04:33 AM, irukandji wrote:
>> Hi everyone, sorry for sending this mail but i wasnt able to find the
>> answer anywhere else.
>>
>> I dont want to make a wrapper around multimap or convert the data to a
>> table as this brings
>> useless copying of data, so the idea was to export the std::pair class
>> and use it as it is
>> from multimap iterators. The ::first is working just fine and outputs
>> the data stored as a key, but
>> the ::second fails and i am unable to figure out why. Can anyone maybe
>> at least say that this is
>> not possible so i can stop banging my head against the wall? :) Thank
>> you in advance...
>>
>> // c++ part
>> std::multimap<std::string, std::string>   m_multimap;
>>
>> luabind::module(pLuaState)
>> [
>> 	luabind::class_<   std::pair<const std::string, std::string>   >
>> ("MultimapPair")
>> 	.property("key",&std::pair<const std::string, std::string>::first )
>> 	.property("val",&std::pair<const std::string, std::string>::second )
>> ];
>>
>> luabind::module(pLuaState)
>> [
>> 	luabind::class_<CTest>("CTest")
>> 	.def_readwrite("multimap",&CTest::m_multimap,
>> luabind::return_stl_iterator)
>> ];
>>
>> // luapart
>> function testclass( ctest )
>>      for data in ctest.multimap do
>>         trace(data.key)
>>         trace(data.value)
>>      end
>> end
>>
>>
>>
>> ------------------------------------------------------------------------------
>> Keep Your Developer Skills Current with LearnDevNow!
>> The most comprehensive online learning library for Microsoft developers
>> is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
>> Metro Style Apps, more. Free future releases when you subscribe now!
>> http://p.sf.net/sfu/learndevnow-d2d
>> _______________________________________________
>> luabind-user mailing list
>> [email protected]
>> https://lists.sourceforge.net/lists/listinfo/luabind-user
>
> ------------------------------------------------------------------------------
> Keep Your Developer Skills Current with LearnDevNow!
> The most comprehensive online learning library for Microsoft developers
> is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
> Metro Style Apps, more. Free future releases when you subscribe now!
> http://p.sf.net/sfu/learndevnow-d2d
> _______________________________________________
> luabind-user mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/luabind-user

------------------------------------------------------------------------------
Keep Your Developer Skills Current with LearnDevNow!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-d2d

_______________________________________________
luabind-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/luabind-user
luabind_stl.zip (application/zip, 6.1 KB) - not displayed