lua-users home
lua-l archive

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

> f 3  => f(3)
> then we could write
> function plus(a) return function (b) return %a + b end end
> plus 3 4
> ...but this is not legal syntax. You have to write plus(3), 
> and then can't
> apply the result directly to 4, so you need:
> a = plus(3)
> a(4)

You can do that by changing two sections of the code ('lparser.c'):

first is in function 'var_or_func', line 457: add the line
      case TK_NUMBER:

second, in function 'funcargs', line 412, add the lines
    case TK_NUMBER: {  /* funcargs -> NUMBER */
      Number r = ls->t.seminfo.r;
      luaK_number(fs, r);

to test, just a little change in your example:

function plus(a) return function (b) print (%a + b) end end
plus 3 4

I'm changing the parser and doing things similar to these.
I have a question to the Lua experts: do changes like these break the
grammar ?