[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: [5.0] trying to auto init a nil field on first ref...
- From: "Leandro Candido" <enclle@...>
- Date: Fri, 12 Dec 2003 02:51:12 -0200
Hello all,
Or this version:
meta_ret = {}
function meta_ret.__index( self, index )
if index == "top" or index == "left" or index == "right" or index ==
"botton" then
return 0;
end
return nil;
end
myRet = {}
setmetatable(myRet,meta_ret);
myRet.top = myRet.top + 10;
print("myRet.top = ",myRet.top);
The God's Peace,
Leandro.
----- Original Message -----
From: "scott" <scott+lua@escherichia.net>
To: "Lua list" <lua@bazar2.conectiva.com.br>
Sent: Friday, December 12, 2003 2:37 AM
Subject: Re: [5.0] trying to auto init a nil field on first ref...
> On Thu, Dec 11, 2003 at 08:15:22PM -0800, Ando Sonenblick wrote:
> >
> > r = {}
> > r.top = r.top + 10
> > print(r.top)
> >
>
> r = {}
> r.top = (r.top or 0) + 10
> print(r.top)
>
> would give you the results that you are looking for, but forces you to
> change your second line a bit, which may not be exactly what you wanted.
>
> scott
>
> --
>
>