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 <> 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...


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;
    switch(ls->t.token) {
      case '(': case TK_STRING: case '{': {
        singlevaraux(fs, ls->envn, &key, 1);
      default: {
        checkname(ls, &key);
        luaK_self(fs, v, &key);
    funcargs(ls, v, line);