lua-users home
lua-l archive

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


On Sep 3, 2010, at 2:43 AM, Jerome Vuarand wrote:

> The Lua syntax is very flexible. The above example can be written :
> 
> button { 'foo', text = "Foo", x = 10, y = 20 }
> 
> With a custom metatable on _G (__index = function(_, k) return k end),
> you could even have :
> 
> button { foo, text = Foo, x = 10, y = 20 }
> 
> And for something a little more advanced, you can use token filters,
> which stays simple enough to design, reuses the Lua parser as much as
> possible, and still directly gives you Lua objects.

I think periodically about doing this or related things when using Lua as a DSL. The problem is that when I have my view description embedded into the rest of my script -- a benefit when using Lua v having to maintain a separate file just for the view description -- I don't want this behavior elsewhere and in fact it interferes with lint checks for globals.

Thinking about this further, code written in this style expects to be run in a special environment. What if instead it were compiled in a special environment? The 5.2 approach to globals says that a global reference "foo" gets translated into "_ENV.foo". The above logic says that a global reference "foo" gets translated into "'foo'". (That's not going to work very well with "button" above, by the way but a call metamethod on strings could take care of that.) A globals lint throws an error when asked to translate a global reference it doesn't understand.

These thoughts are far from complete and they play back into subjects like table scopes (http://lua-users.org/wiki/TableScope), but it certainly feels like there is something trying to fight its way out to the surface here.

Mark