lua-users home
lua-l archive

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


On Fri, Jan 13, 2017 at 8:57 PM, 常严 <changy@sibet.ac.cn> wrote:
> What I means is that can we define a simple syntactic function as
> `
> variable#
> `
> and it will be mapped to a function doing something:
> `
> function test(variable)
> for i =1, #variable do
> ...
> end
> end
> `
> Using the short notation is easy for user to do some specific loop
> operation.

Lua does not have any mechanisms for this.

If you want to do something like that, you'll either need to modify
the parser or use a token filter of some sort. These techniques are
fairly well-known in the community (I don't know how to do it myself,
but I'm sure it's on the wiki) but they're not available using JUST
the vanilla Lua interpreter.

/s/ Adam