aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ldo.c11
-rw-r--r--ldo.h4
-rw-r--r--lvm.c6
3 files changed, 8 insertions, 13 deletions
diff --git a/ldo.c b/ldo.c
index 1abd105c..dd2ecb89 100644
--- a/ldo.c
+++ b/ldo.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ldo.c,v 2.184 2017/12/28 14:17:09 roberto Exp roberto $ 2** $Id: ldo.c,v 2.185 2017/12/29 15:44:51 roberto Exp roberto $
3** Stack and Call structure of Lua 3** Stack and Call structure of Lua
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -327,18 +327,15 @@ static void rethook (lua_State *L, CallInfo *ci) {
327** it in stack below original 'func' so that 'luaD_call' can call 327** it in stack below original 'func' so that 'luaD_call' can call
328** it. Raise an error if __call metafield is not a function. 328** it. Raise an error if __call metafield is not a function.
329*/ 329*/
330StkId luaD_tryfuncTM (lua_State *L, StkId func) { 330void luaD_tryfuncTM (lua_State *L, StkId func) {
331 const TValue *tm = luaT_gettmbyobj(L, s2v(func), TM_CALL); 331 const TValue *tm = luaT_gettmbyobj(L, s2v(func), TM_CALL);
332 StkId p; 332 StkId p;
333 if (!ttisfunction(tm)) 333 if (!ttisfunction(tm))
334 luaG_typeerror(L, s2v(func), "call"); 334 luaG_typeerror(L, s2v(func), "call");
335 /* Open a hole inside the stack at 'func' */
336 checkstackp(L, 1, func); /* ensure space for metamethod */
337 for (p = L->top; p > func; p--) 335 for (p = L->top; p > func; p--)
338 setobjs2s(L, p, p-1); 336 setobjs2s(L, p, p-1);
339 L->top++; 337 L->top++; /* assume EXTRA_STACK */
340 setobj2s(L, func, tm); /* metamethod is the new function to be called */ 338 setobj2s(L, func, tm); /* metamethod is the new function to be called */
341 return func;
342} 339}
343 340
344 341
@@ -489,7 +486,7 @@ void luaD_call (lua_State *L, StkId func, int nresults) {
489 break; 486 break;
490 } 487 }
491 default: { /* not a function */ 488 default: { /* not a function */
492 func = luaD_tryfuncTM(L, func); /* try to get '__call' metamethod */ 489 luaD_tryfuncTM(L, func); /* try to get '__call' metamethod */
493 luaD_call(L, func, nresults); /* now it must be a function */ 490 luaD_call(L, func, nresults); /* now it must be a function */
494 break; 491 break;
495 } 492 }
diff --git a/ldo.h b/ldo.h
index 765f6cef..50f79242 100644
--- a/ldo.h
+++ b/ldo.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ldo.h,v 2.37 2017/12/08 17:28:25 roberto Exp roberto $ 2** $Id: ldo.h,v 2.38 2017/12/11 12:43:40 roberto Exp roberto $
3** Stack and Call structure of Lua 3** Stack and Call structure of Lua
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -51,7 +51,7 @@ LUAI_FUNC void luaD_hook (lua_State *L, int event, int line);
51LUAI_FUNC void luaD_pretailcall (lua_State *L, CallInfo *ci, StkId func, int n); 51LUAI_FUNC void luaD_pretailcall (lua_State *L, CallInfo *ci, StkId func, int n);
52LUAI_FUNC void luaD_call (lua_State *L, StkId func, int nResults); 52LUAI_FUNC void luaD_call (lua_State *L, StkId func, int nResults);
53LUAI_FUNC void luaD_callnoyield (lua_State *L, StkId func, int nResults); 53LUAI_FUNC void luaD_callnoyield (lua_State *L, StkId func, int nResults);
54LUAI_FUNC StkId luaD_tryfuncTM (lua_State *L, StkId func); 54LUAI_FUNC void luaD_tryfuncTM (lua_State *L, StkId func);
55LUAI_FUNC int luaD_pcall (lua_State *L, Pfunc func, void *u, 55LUAI_FUNC int luaD_pcall (lua_State *L, Pfunc func, void *u,
56 ptrdiff_t oldtop, ptrdiff_t ef); 56 ptrdiff_t oldtop, ptrdiff_t ef);
57LUAI_FUNC void luaD_poscall (lua_State *L, CallInfo *ci, StkId firstResult, 57LUAI_FUNC void luaD_poscall (lua_State *L, CallInfo *ci, StkId firstResult,
diff --git a/lvm.c b/lvm.c
index 8ba7f1c7..bdea807f 100644
--- a/lvm.c
+++ b/lvm.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lvm.c,v 2.331 2017/12/30 20:46:18 roberto Exp roberto $ 2** $Id: lvm.c,v 2.332 2018/01/09 14:23:40 roberto Exp roberto $
3** Lua virtual machine 3** Lua virtual machine
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -1501,9 +1501,7 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
1501 b = L->top - ra; 1501 b = L->top - ra;
1502 lua_assert(GETARG_C(i) - 1 == LUA_MULTRET); 1502 lua_assert(GETARG_C(i) - 1 == LUA_MULTRET);
1503 if (!ttisfunction(vra)) { /* not a function? */ 1503 if (!ttisfunction(vra)) { /* not a function? */
1504 /* try to get '__call' metamethod */ 1504 ProtectNT(luaD_tryfuncTM(L, ra)); /* try '__call' metamethod */
1505 ProtectNT(ra = luaD_tryfuncTM(L, ra));
1506 vra = s2v(ra);
1507 b++; /* there is now one extra argument */ 1505 b++; /* there is now one extra argument */
1508 } 1506 }
1509 if (!ttisLclosure(vra)) { /* C function? */ 1507 if (!ttisLclosure(vra)) { /* C function? */