Lua 5.1.4
For example:
bar = {}
bar.name = 'test'
bar['123.com'] = function(self) print(self.name) end
I can’t call the method like below:
bar:['123.com']()
stdin:1: '<name>' expected near '['
Althought below works:
bar['123.com'](bar)
But I this is somehow ugly. Is there a syntax sugar for this situation?
Or if it really cannot do it, will Lua team add this syntax in future?
Or they did this intentionally?
Nobody knows what the Lua maintainers will add in future versions (they’re pretty close-mouthed), but my guess would be that it’s unlikely they’ll add it without at least being asked—and I’ve never seen a request for such a thing on the Lua mailing list…
My intuition, though, is that this functionality seems obscure: how often do people really want to call methods with “weird” names like that? Given that, and that the “workaround” really isn’t bad at all, it’s unclear whether it’s worth adding complexity to the implementation to support such a feature (unless it’s completely trivial).
If you want to try asking, you should post about it to the Lua mailing list, which is where most such discussion takes place:
lua-l@lists.lua.org