Re: adding fields to lua class from C++
"Domino" <[email protected]>
| Newsgroups | gmane.comp.lang.lua.bind.user |
|---|---|
| Message-ID | <000301c9ba9a$40b36b80$c21a4280$@fm> |
Hi, Thanks, but unfortunately this didn't answer my question. I did not ask how to do this from the design point of view but how to ensure that the code: if (m_Self[field_name]) won't fail. In other words how to force lua table to create entry "field_name" from the C++ side? From the design point of view I've chosen that it's C++ duty as I don't want to force script creator to first create fields and then add them to dynamic fields list. It's simpler to have only dynamic fields and force lua to put the field into table from C++ side. Thanks From: yaohua xiao [mailto:[email protected]] Sent: Friday, April 10, 2009 2:46 AM To: [email protected] Subject: Re: [luabind] adding fields to lua class from C++ I think it's a design problem. When you decided what c++ or lua's duty in your project, the problem is clear. In my opinion, i will use a std::map<string,string> to store the key-field pairs and exports a get/set method to lua. in your case: function myClass:populateDynamicFields( ) addDynamicField('field1', int) addDynamicField('field2', string) end It seems that the fields will be different types, so I suggest to use the string type to store field value, and translate it when you use it. 2009/4/9 <[email protected]> Message: 5 Date: Mon, 6 Apr 2009 20:47:37 +0200 From: "Domino" <[email protected]> Subject: [luabind] adding fields to lua class from C++ To: <[email protected]> Message-ID: <000001c9b6e8$27f70da0$77e528e0$@fm> Content-Type: text/plain; charset="us-ascii" Hi all, I'm working on pseudo-dynamic fields for the lua classes. What I want to achieve is some sort of mapping of object fields available from C++. So my script class will populate the fields map like: function myClass:populateDynamicFields() addDynamicField('field1', int) addDynamicField('field2', string) end then from GUI I want to display this list of dynamic fields and be able to set their values via get/setValueInt (eventually I would like to add fields from GUI as well). These methods will basically look like below: void myClassInterface::setValueInt(string name, int value) { // let's say that I have luabind::object that is the script class representation in luabind and it's called m_Self if (m_Self[name]) { m_Self[name] = value; } } What I don't know is how to ensure that the m_Self[name] exists? Or how to force its creation from C++ side? Like: // . if (!m_Self[name]) // do something to create field Is there some way to do this? Or maybe there is some more generic way to do what I'm trying here? Thanks a lot. ------------------------------------------------------------------------------ This SF.net email is sponsored by: High Quality Requirements in a Collaborative Environment. Download a free trial of Rational Requirements Composer Now! http://p.sf.net/sfu/www-ibm-com _______________________________________________ luabind-user mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/luabind-user