lua-users home
lua-l archive

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



On Fri, Feb 17, 2012 at 5:29 PM, Sven Olsen <sven2718@gmail.com> wrote:
Though maybe I'm taking the quest for implicit self semantics a little far at this point...

Alright, so, just because I can't seem to keep myself from fiddling with this... I think a similar terse-member function call syntax that wouldn't provoke any parser weirdness would be to use a trailing colon to indicate that a call should begin with an implicit _ENV parameter.  And that syntax seems easy to implement via a short diff in the ':' case of primaryexp...

-Sven

PS: I fear that I now have just enough understanding of the parser to start really getting myself into trouble; but, as best as I can tell, this little diff does properly convert calls of the form "f:(...)" to "f(_ENV,...)".  My sense, after poking around in the sources, is that just pushing the function _expression_ onto the register list, followed by _ENV, and then calling funcargs() should be sufficient to implement the transform; and it seems to work fine in practice...

  case ':': {  /* `:' NAME funcargs */
    expdesc key;
    luaX_next(ls);
    switch(ls->t.token) {
      case '(': case TK_STRING: case '{': {
        singlevaraux(fs, ls->envn, &key, 1);
        luaK_exp2nextreg(fs,v);
        luaK_exp2nextreg(fs,&key);
        break;
      }
      default: {
        checkname(ls, &key);
        luaK_self(fs, v, &key);
        break;
      }
    }
    funcargs(ls, v, line);
    break;
  }