[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: [5.0] trying to auto init a nil field on first ref...
- From: "Eric Raible" <raible@...>
- Date: Fri, 12 Dec 2003 12:33:07 -0800 (PST)
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