structlua_State { CommonHeader; lu_byte status; StkId top; /* first free slot in the stack */ StkId base; /* base of current function */ global_State *l_G; CallInfo *ci; /* call info for current function */ const Instruction *savedpc; /* `savedpc of current function */ StkId stack_last; /* last free slot in the stack */ StkId stack; /* stack base */ CallInfo *end_ci; /* points after end of ci array*/ CallInfo *base_ci; /* array of CallInfos */ int stacksize; int size_ci; /* size of array `base_ci */ unsignedshort nCcalls; /* number of nested C calls */ unsignedshort baseCcalls; /* nested C calls when resuming coroutine */ lu_byte hookmask; lu_byte allowhook; int basehookcount; int hookcount; lua_Hook hook; TValue l_gt; /* table of globals */ TValue env; /* temporary place for environments */ GCObject *openupval; /* list of open upvalues in this stack */ GCObject *gclist; structlua_longjmp *errorJmp;/* current error recover point */ ptrdiff_t errfunc; /* current error handling function (stack index) */ };
TValue *oldval = luaH_set(L, h, key); /* do a primitive set */
if (!ttisnil(oldval) || /* result is no nil? */ (tm = fasttm(L, h->metatable, TM_NEWINDEX)) == NULL) { /* or no TM? */ setobj2t(L, oldval, val); luaC_barriert(L, h, val); return; }
再看luaH_set:
1 2 3 4 5 6 7 8 9 10 11
const TValue *p = luaH_get(t, key); flags = 0; if (p != luaO_nilobject) returncast(TValue *, p); else { if (ttisnil(key)) luaG_runerror(L, "table index is nil"); elseif (ttisnumber(key) luai_numisnan(nvalue(key))); luaG_runerror(L, "table index is NaN"); returnnewkey(L, t, key); }