diff -urN lua-5.0/src/ltm.c lua_new/src/ltm.c --- lua-5.0/src/ltm.c 2003年04月03日 08:35:34.000000000 -0500 +++ lua_new/src/ltm.c 2003年04月12日 10:24:20.000000000 -0400 @@ -28,6 +28,9 @@ void luaT_init (lua_State *L) { static const char *const luaT_eventname[] = { /* ORDER TM */ "__index", "__newindex", +/* Begin */ + "__newtable", "__newfunction", +/* End */ "__gc", "__mode", "__eq", "__add", "__sub", "__mul", "__div", "__pow", "__unm", "__lt", "__le", diff -urN lua-5.0/src/ltm.h lua_new/src/ltm.h --- lua-5.0/src/ltm.h 2002年11月14日 06:51:50.000000000 -0500 +++ lua_new/src/ltm.h 2003年04月12日 10:24:20.000000000 -0400 @@ -18,6 +18,10 @@ typedef enum { TM_INDEX, TM_NEWINDEX, +/* Begin */ + TM_NEWTAB, + TM_NEWFUNC, +/* End */ TM_GC, TM_MODE, TM_EQ, /* last tag method with `fast' access */ diff -urN lua-5.0/src/lvm.c lua_new/src/lvm.c --- lua-5.0/src/lvm.c 2003年04月03日 08:35:34.000000000 -0500 +++ lua_new/src/lvm.c 2003年04月12日 10:24:20.000000000 -0400 @@ -119,6 +119,22 @@ luaD_call(L, L->top - 4, 0); } +/* Begin */ +static void callTM_new (lua_State *L, const TObject *f, + const TObject *p1, const TObject *p2) { + setobj2s(L->top, f); /* push function */ + setobj2s(L->top+1, p1); /* 1st argument */ + setobj2s(L->top+2, p2); /* 2nd argument */ + luaD_checkstack(L, 3); /* cannot check before (could invalidate p1, p2) */ + L->top += 3; + luaD_call(L, L->top - 3, 0); +} + +void luaV_new(lua_State *L, const TObject *env, const TObject *t, int tms) { + const TObject *tm = fasttm(L, hvalue(env)->metatable, tms); + if (tm && ttisfunction(tm)) callTM_new(L, tm, env, t); +} +/* End */ static const TObject *luaV_index (lua_State *L, const TObject *t, TObject *key, int loop) { @@ -499,6 +515,9 @@ b = fb2int(b); sethvalue(ra, luaH_new(L, b, GETARG_C(i))); luaC_checkGC(L); +/* Begin */ + luaV_new(L, &cl->g, ra, TM_NEWTAB); +/* End */ break; } case OP_SELF: { @@ -772,6 +791,9 @@ } setclvalue(ra, ncl); luaC_checkGC(L); +/* Begin */ + luaV_new(L, &cl->g, ra, TM_NEWFUNC); +/* End */ break; } }