lua-users home
lua-l archive

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


Hello,

Something that I always desired (and would not be intrusive) was to allow commas to be also accepted before the items, and not only after:

t = {
    , xxx = yyy
    , www = zzz
}

Instead of:

t = {
      xxx = yyy
    , www = zzz
}

abs,
Francisco

On Jan 23, 2008 2:42 PM, Mark Hamburg < mhamburg@adobe.com> wrote:
I too have wanted support for writing function declarations in tables more
compactly. However, there's probably an interesting question as to whether
it should auto translate into the form that takes self as a first argument.
One alterative would be:

Box = {

   function notAMethod()
       print "I'm just a function in the Box namespace"
   end,

   function :method()
       print( string.format( "I'm a method of: %s", tostring( self ) ) )
   end

}

I agree with the suggestion that finding a way to get rid of the commas
would definitely be desirable.

This all leads to the broader subject of whether there should be a syntax
that supports more control constructs and arbitrary code inline while
building tables. It would feel more "data description"-ish. No formal
proposals at this time...

Mark

on 1/23/08 5:33 AM, alex.mania@iinet.net.au at 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. =)
>
>