lua-users home
lua-l archive

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


So '@width' is to be expanded as 'self.width'?

function __init(width, height, depth)

is of course exactly the same as

__init = function(self, width, height, depth)

self is fine; we know what it means, and can teach our editors to spit
it out with a keystroke ;)

steve d.

On Jan 23, 2008 3:33 PM, alex.mania@iinet.net.au
<alex.mania@iinet.net.au> wrote:
>  Hey all,
>
>  Just wondering if anyone else would be interested in a couple of the minor
> changes I've made to the Lua core,
>  which essentially allows constructs like this:
>
>   local Box = class{
>     classname = "Box",
>     inherits = Shape,
>
>     function __init(width, height, depth)
>       @width = width
>       @height = height
>       @depth = depth
>     end
>   }
>
>  to be equivalent to:
>
>   local Box = class{
>     classname = "Box",
>     inherits = Shape,
>
>     __init = function(self, width, height, depth)
>       self.width = width
>       self.height = height
>       self.depth = depth
>     end
>   }
>
>  The @ symbol is not my idea, I believe there's macros that accomplish much
> the same thing.
>
>  If everybody's happy as is / macros are fine then it saves me the trouble
> of learning how to use
>  diff (it probably should be innate knowledge in any programmer.. most
> embarrassing) and posting
>  it on the powerpatches page. =)
>
>