[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Lua function syntax sugar for a digit started function name?
- From: "William C. Bubel" <wcbubel@...>
- Date: Thu, 19 Apr 2012 19:35:48 -0400
On 04/19/2012 10:10 AM, y s wrote:
> Lua 5.1.4
> 
> For example:
> 
>     |bar = {} 
>     bar.name = 'test' 
>     bar['123.com <http://123.com>'] = function(self) print(self.name) end 
>     |
> 
> I can't call the method like below:
> 
>     |bar:['123.com <http://123.com>']() 
>     stdin:1: '<name>' expected near '[' 
>     |
Maybe this solution might help.
  bar = {}
  bar.name = 'test'
  bar['123.com <http://123.com>'] = function(self) print(self.name) end
  -- Make bar behave like a function
  setmetatable(bar,{__call=function(t, k, ...) return t[k](t,...) end})
  bar('123.com <http://123.com>')