lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Ivo Beltchev wrote:
The coder in me tends to agree. However this system is intended to be used by non-programmers and should be as simple and as robust as possible. For example I have a text box where they can type a criteria for searching objects. The text can be as simple as "return obj.mass>20" (give me all objects that have a mass>20). I want to minimize the possibility for syntax and runtime errors.

Don't metatables for userdata give you a hand here?

you make __index for the object return nil or some other marker
so that you can determine if the object has the property first.

If not, then you don't do the compare.

When the user types "return obj.mass>20" they are really asking
two questions:

1. Does this object have a mass
2. Is the mass > 20

Ralph