lua-users home
lua-l archive

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


y s <y.s.outside@gmail.com> wrote:
>
>  I can't call the method like below:
>
> > bar:['123.com']()

Try the patch below.

Tony.
-- 
f.anthony.n.finch  <dot@dotat.at>  http://dotat.at/
Hebrides: East or northeast 3 or 4, becoming cyclonic 4 or 5. Moderate or
rough. Rain or showers. Moderate or good.


diff --git a/src/lcode.c b/src/lcode.c
index 6194749..0ae8722 100644
--- a/src/lcode.c
+++ b/src/lcode.c
@@ -500,16 +500,16 @@ void luaK_storevar (FuncState *fs, expdesc *var, expdesc *ex) {
 }


-void luaK_self (FuncState *fs, expdesc *e, expdesc *key) {
-  int func;
+void luaK_self1 (FuncState *fs, expdesc *e) {
   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));
+}
+
+
+void luaK_self2 (FuncState *fs, expdesc *e, expdesc *key) {
+  luaK_codeABC(fs, OP_SELF, e->u.s.info, e->u.s.info, luaK_exp2RK(fs, key));
   freeexp(fs, key);
-  e->u.s.info = func;
-  e->k = VNONRELOC;
 }


diff --git a/src/lcode.h b/src/lcode.h
index b941c60..80b3c4e 100644
--- a/src/lcode.h
+++ b/src/lcode.h
@@ -55,7 +55,8 @@ LUAI_FUNC int luaK_exp2anyreg (FuncState *fs, expdesc *e);
 LUAI_FUNC void luaK_exp2nextreg (FuncState *fs, expdesc *e);
 LUAI_FUNC void luaK_exp2val (FuncState *fs, expdesc *e);
 LUAI_FUNC int luaK_exp2RK (FuncState *fs, expdesc *e);
-LUAI_FUNC void luaK_self (FuncState *fs, expdesc *e, expdesc *key);
+LUAI_FUNC void luaK_self1 (FuncState *fs, expdesc *e);
+LUAI_FUNC void luaK_self2 (FuncState *fs, expdesc *e, expdesc *key);
 LUAI_FUNC void luaK_indexed (FuncState *fs, expdesc *t, expdesc *k);
 LUAI_FUNC void luaK_goiftrue (FuncState *fs, expdesc *e);
 LUAI_FUNC void luaK_storevar (FuncState *fs, expdesc *var, expdesc *e);
diff --git a/src/lparser.c b/src/lparser.c
index 7ff0925..956b46e 100644
--- a/src/lparser.c
+++ b/src/lparser.c
@@ -780,8 +780,12 @@ static void primaryexp (LexState *ls, expdesc *v) {
       case ':': {  /* `:' NAME funcargs */
         expdesc key;
         luaX_next(ls);
-        checkname(ls, &key);
-        luaK_self(fs, v, &key);
+        luaK_self1(fs, v);
+        if (ls->t.token == '[')
+          yindex(ls, &key);
+        else
+          checkname(ls, &key);
+        luaK_self2(fs, v, &key);
         funcargs(ls, v);
         break;
       }