Re: adding fields to lua class from C++

yaohua xiao <[email protected]>
Newsgroups gmane.comp.lang.lua.bind.user
Message-ID <[email protected]>
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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.