lua-users home
lua-l archive

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


As a first post, I'll start small...

I like the idea of __index simply being a table,
but it seemed appropriate to catch assignments to
non-existent fields:

r = setmetatable({}, {__index = {top = 10, bottom = 0, left = 0, right = 0},
                      __newindex = function( self, key, val )
                        if self[key] and type(val)=="number" then
                          rawset(self,key,val)
                        else
                          error(string.format("Invalid assignment %s=%s",
                             key, tostring(val)),2)
                        end
                      end})

- Eric