lua-users home
lua-l archive

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


I have written a module called schema [1] to help me figure a generic
way of declaring DSLs to use with my ORM 'Loft' [2].

I found it an interesting technique to use the index metamethod to
capture field names, so I wouldn't have to patch Lua or build a
pattern.

The thing goes like this:

Schema 'default' {
  Type 'Point'
    .x : Number{is='rw', default='0'}
    .y : Number{is='rw', default='0'}
  ;
  Type 'Area'
    .name -- defaults to string
    .start : Point()
    .end  : Point()
  ;
}

Luís Eduardo Jason Santos

[1] http://luaforge.net/projects/schema/
[2] http://luaforge.net/projects/loft/

On Tue, Aug 18, 2009 at 3:06 AM, steve donovan<steve.j.donovan@gmail.com> wrote:
> On Tue, Aug 18, 2009 at 5:22 AM, David Manura<dm.lua@math2.org> wrote:
>>  has.x { is = 'rw', isa = 'number', default = 0 }
>>
>
> Yes, that's a good example of Lua being used creatively.
>
> If there is a default, then usually 'isa' can be easily auto-detected;
> there can be a default for 'is' as well.
>
> Can then have the default notation:
>
> has.x (0)
>