Quote Originally Posted by paul_nicholls
Quote Originally Posted by jdarling
If you write an __newindex handler (writer) that uses RTTI to look at the parent class and write a specialized __index handler (reader) then you can emulate properties quite well. I have this working some place, but the method callers arn't complete yet. Actually the code above gives me some ideas so I may be posting up my code for LUA some time soon too
I was thinking about '__index' as well, but as far as I can figure this would only help with making readable properties, not writable ones

How would using '__newindex' help with emulating properties? This is only called if one is adding a new key + value to a table, not for pre-existing keys...

I would be interested in how you got the '__newindex' working for this sort of thing

Also I have no clue as to if it is even possible to protect the existing 'class methods' created in the table from being accidently overwritten by a lua script using the table and assigning a value to that key...

Any thoughts on that one?

cheers,
Paul.
Just as soon as I have the code completed and cleaned up I'll post it up for everyone to use. The basic idea is this:

Create your "Class" using the methods provided in Luna thus hiding the metatable and object level manager from the Lua script in general. Overide the __index and __newindex (witch fires when an unknown is set) and make sure that ALL properties are removed from the meta table. Any time a person makes a request to the object using dot notation either __index (read) or __newindex (write) will be fired, using RTTI scan the object and find out if the property exists, if so then return/set the value otherwise throw an error or pass it back up to Lua as a new table entitity using lua_settable(L, TableIndex) lua_pushstring(L, [PropName]) lua_pushvalue(L, val). Thus the next time its accessed it won't fire __index or __newindex, since you have caught the ones that do fire these "events" (and I use the term loosly) your code will still execute. Now before you ask what if the person overrides __index or __newindex remember that we hid the MetaTable and ObjectTable from the user, they can still get at it using upval() but thats another topic for another day. You simply have to let your users know not to screw with the __index and __newindex methods attached to your objects