Luabridge C + + returns map to Lua

Source: Internet
Author: User
Tags gettext lua

prior to returning a std::map<std::string,std::string> to Lua in the project, it was not possible to find the direct return map to Lua. Later through the help of others finally solved the problem. Here's how:

1 luabridge::luaref loginxml::getlocalaccount ()2 {3xmlelement* Rootele = pdoc->rootelement ();4xmlelement* Accountele = rootele->firstchildelement ("LocalAccount");5xmlelement* Childele = accountele->firstchildelement ();6      while(Childele)7     {8STD::stringStrName = Childele->firstchildelement (" Account"),GetText ();9STD::stringStrpwd = Childele->firstchildelement ("Password"),GetText ();TenAccountmap.insert (STD::MAP&LT;STD::string, std::string>:: Value_type (StrName, strpwd)); OneChildele = childele->nextsiblingelement (); A     } -      -lua_state* luastate = Globalscriptmanager.get_lua_state ();//Get Lua_state the  -Luabridge::luaref uniforms (luastate, luabridge::newtable (luastate));//returns a value of one table -  -STD::MAP&LT;STD::string, std::string>:: iterator iter; +      for(iter = Accountmap.begin (); ITER! = Accountmap.end (); iter++) -     { +STD::stringStrName = iter->First ; ASTD::stringStrpwd = iter->second; atUniforms[strname] = strpwd;//Insert value to uniforms -     } -  -     returnuniforms; -}

Just call it right in Lua ...

Loginui.accountlist = loginxml:getlocalaccount ()        for inpairs do            local txt = uiforlua:createtext (k," Microsoft Jas Black ")                    LoginUI.listAccount:pushBackCustomItem (TXT)        End

Luabridge C + + returns map to Lua

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.