In primaryexp (lparser.c), the colon operator case becomes:
case ':': { /* `:' NAME funcargs */
expdesc key;
luaX_next(ls);
/* PATCH: Add support for obj:[ exp ] syntax for calling methods. */
if (ls->t.token == '[') {
yindex(ls, &key);
}
else {
checkname(ls, &key);
}
luaK_self(fs, v, &key);
/* Compiles each expression evaluating them into a sequence of
registers. */
switch (ls->t.token) { /* PATCH: Check for a call before
going to the funcargs case, otherwise curry. */
case '(': case TK_STRING: case '{': { /* funcargs */
funcargs(ls, v);
break;
}
default: {
currymethod(ls, v);
return;
}
}
break;
}
I'm afraid I don't have an implementation for currymethod. Without
that support, the inner switch just becomes a call to funcargs(ls,v).
But to get the rest of obj:[ method ] working one also needs to
revise luaK_self in lcode.c:
void luaK_self (FuncState *fs, expdesc *e, expdesc *key) {
int func;
luaK_exp2anyreg(fs, e);
freeexp(fs, e);
func = fs->freereg;
luaK_reserveregs(fs, 2);
luaK_codeABC(fs, OP_SELF, func, e->u.s.info, luaK_exp2RK(fs, key));
freeexp(fs, key);
fs->freereg = func + 2; /* PATCH: Make sure that freeing the key
won't have just cost us a register. Why??? */
e->u.s.info = func;
e->k = VNONRELOC;
}
As the comments, suggest it would be good to have someone who knows
the register behavior in the Lua code generator better than I review
this code.