--- C:/Users/John/AppData/Local/Temp/ltm.h-revBASE.svn000.tmp.h Sat Aug 4 14:44:36 2012 +++ E:/Projects/Grunt/Grunt/LuaSrc/ltm.h Sat Aug 4 16:02:43 2012 @@ -33,6 +33,9 @@ TM_LE, TM_CONCAT, TM_CALL, +#if defined(JH_LUA_ITER) + TM_ITER, +#endif TM_N /* number of elements in the enum */ } TMS; --- C:/Users/John/AppData/Local/Temp/ltm.c-revBASE.svn000.tmp.c Sat Aug 4 14:44:36 2012 +++ E:/Projects/Grunt/Grunt/LuaSrc/ltm.c Sat Aug 4 16:02:39 2012 @@ -36,6 +36,9 @@ "__add", "__sub", "__mul", "__div", "__mod", "__pow", "__unm", "__lt", "__le", "__concat", "__call" +#if defined(JH_LUA_ITER) + ,"__iter" +#endif }; int i; for (i=0; iu.l.savedpc += GETARG_sBx(i); ) +#if defined(JH_LUA_ITER) vmcasenb(OP_TFORCALL, StkId cb = ra + 3; /* call base */ + if (!ttisfunction(ra)) + { + const TValue *tm = luaT_gettmbyobj(L, ra, TM_ITER); + if (ttisfunction(tm)) + { + setobjs2s(L, cb, tm); + } + else + { + L->top = cb; + lua_getglobal(L, "pairs"); + if (!ttisfunction(cb)) luaG_typeerror(L, ra, "iterate"); + } + setobjs2s(L, cb+1, ra); + L->top = cb + 2; + Protect(luaD_call(L, cb, 3, 1)); + L->top = L->ci->top; + ra = RA(i); + cb = ra + 3; + setobj2s(L, ra+2, cb+2); + setobj2s(L, ra+1, cb+1); + setobj2s(L, ra, cb); + L->top = ra + 3; + } setobjs2s(L, cb+2, ra+2); setobjs2s(L, cb+1, ra+1); setobjs2s(L, cb, ra); @@ -802,6 +819,21 @@ lua_assert(GET_OPCODE(i) == OP_TFORLOOP); goto l_tforloop; ) +#else + vmcasenb(OP_TFORCALL, + StkId cb = ra + 3; /* call base */ + setobjs2s(L, cb+2, ra+2); + setobjs2s(L, cb+1, ra+1); + setobjs2s(L, cb, ra); + L->top = cb + 3; /* func. + 2 args (state and index) */ + Protect(luaD_call(L, cb, GETARG_C(i), 1)); + L->top = ci->top; + i = *(ci->u.l.savedpc++); /* go to next instruction */ + ra = RA(i); + lua_assert(GET_OPCODE(i) == OP_TFORLOOP); + goto l_tforloop; + ) +#endif vmcase(OP_TFORLOOP, l_tforloop: if (!ttisnil(ra + 1)) { /* continue loop? */

AltStyle によって変換されたページ (->オリジナル) /