This commit is contained in:
iceman1001 2024-09-30 10:36:29 +02:00
parent c3591b9692
commit 71c86f4b21
68 changed files with 18942 additions and 18745 deletions

View file

@ -64,13 +64,11 @@ static TValue *index2value (lua_State *L, int idx) {
api_check(L, idx <= ci->top.p - (ci->func.p + 1), "unacceptable index");
if (o >= L->top.p) return &G(L)->nilvalue;
else return s2v(o);
}
else if (!ispseudo(idx)) { /* negative index */
} else if (!ispseudo(idx)) { /* negative index */
api_check(L, idx != 0 && -idx <= L->top.p - (ci->func.p + 1),
"invalid index");
return s2v(L->top.p + idx);
}
else if (idx == LUA_REGISTRYINDEX)
} else if (idx == LUA_REGISTRYINDEX)
return &G(L)->l_registry;
else { /* upvalues */
idx = LUA_REGISTRYINDEX - idx;
@ -79,8 +77,7 @@ static TValue *index2value (lua_State *L, int idx) {
CClosure *func = clCvalue(s2v(ci->func.p));
return (idx <= func->nupvalues) ? &func->upvalue[idx - 1]
: &G(L)->nilvalue;
}
else { /* light C function or Lua function (through a hook)?) */
} else { /* light C function or Lua function (through a hook)?) */
api_check(L, ttislcf(s2v(ci->func.p)), "caller not a C function");
return &G(L)->nilvalue; /* no upvalues */
}
@ -98,8 +95,7 @@ l_sinline StkId index2stack (lua_State *L, int idx) {
StkId o = ci->func.p + idx;
api_check(L, o < L->top.p, "invalid index");
return o;
}
else { /* non-positive index */
} else { /* non-positive index */
api_check(L, idx != 0 && -idx <= L->top.p - (ci->func.p + 1),
"invalid index");
api_check(L, !ispseudo(idx), "invalid index");
@ -190,8 +186,7 @@ LUA_API void lua_settop (lua_State *L, int idx) {
diff = ((func + 1) + idx) - L->top.p;
for (; diff > 0; diff--)
setnilvalue(s2v(L->top.p++)); /* clear new slots */
}
else {
} else {
api_check(L, -(idx + 1) <= (L->top.p - (func + 1)), "invalid new top");
diff = idx + 1; /* will "subtract" index (as it is negative) */
}
@ -357,10 +352,17 @@ LUA_API int lua_compare (lua_State *L, int index1, int index2, int op) {
o2 = index2value(L, index2);
if (isvalid(L, o1) && isvalid(L, o2)) {
switch (op) {
case LUA_OPEQ: i = luaV_equalobj(L, o1, o2); break;
case LUA_OPLT: i = luaV_lessthan(L, o1, o2); break;
case LUA_OPLE: i = luaV_lessequal(L, o1, o2); break;
default: api_check(L, 0, "invalid option");
case LUA_OPEQ:
i = luaV_equalobj(L, o1, o2);
break;
case LUA_OPLT:
i = luaV_lessthan(L, o1, o2);
break;
case LUA_OPLE:
i = luaV_lessequal(L, o1, o2);
break;
default:
api_check(L, 0, "invalid option");
}
}
lua_unlock(L);
@ -426,11 +428,16 @@ LUA_API const char *lua_tolstring (lua_State *L, int idx, size_t *len) {
LUA_API lua_Unsigned lua_rawlen(lua_State *L, int idx) {
const TValue *o = index2value(L, idx);
switch (ttypetag(o)) {
case LUA_VSHRSTR: return tsvalue(o)->shrlen;
case LUA_VLNGSTR: return tsvalue(o)->u.lnglen;
case LUA_VUSERDATA: return uvalue(o)->len;
case LUA_VTABLE: return luaH_getn(hvalue(o));
default: return 0;
case LUA_VSHRSTR:
return tsvalue(o)->shrlen;
case LUA_VLNGSTR:
return tsvalue(o)->u.lnglen;
case LUA_VUSERDATA:
return uvalue(o)->len;
case LUA_VTABLE:
return luaH_getn(hvalue(o));
default:
return 0;
}
}
@ -446,9 +453,12 @@ LUA_API lua_CFunction lua_tocfunction (lua_State *L, int idx) {
l_sinline void *touserdata(const TValue *o) {
switch (ttype(o)) {
case LUA_TUSERDATA: return getudatamem(uvalue(o));
case LUA_TLIGHTUSERDATA: return pvalue(o);
default: return NULL;
case LUA_TUSERDATA:
return getudatamem(uvalue(o));
case LUA_TLIGHTUSERDATA:
return pvalue(o);
default:
return NULL;
}
}
@ -475,8 +485,10 @@ LUA_API lua_State *lua_tothread (lua_State *L, int idx) {
LUA_API const void *lua_topointer(lua_State *L, int idx) {
const TValue *o = index2value(L, idx);
switch (ttypetag(o)) {
case LUA_VLCF: return cast_voidp(cast_sizet(fvalue(o)));
case LUA_VUSERDATA: case LUA_VLIGHTUSERDATA:
case LUA_VLCF:
return cast_voidp(cast_sizet(fvalue(o)));
case LUA_VUSERDATA:
case LUA_VLIGHTUSERDATA:
return touserdata(o);
default: {
if (iscollectable(o))
@ -581,8 +593,7 @@ LUA_API void lua_pushcclosure (lua_State *L, lua_CFunction fn, int n) {
if (n == 0) {
setfvalue(s2v(L->top.p), fn);
api_incr_top(L);
}
else {
} else {
CClosure *cl;
api_checknelems(L, n);
api_check(L, n <= MAXUPVAL, "upvalue index too large");
@ -642,8 +653,7 @@ l_sinline int auxgetstr (lua_State *L, const TValue *t, const char *k) {
if (luaV_fastget(L, t, str, slot, luaH_getstr)) {
setobj2s(L, L->top.p, slot);
api_incr_top(L);
}
else {
} else {
setsvalue2s(L, L->top.p, str);
api_incr_top(L);
luaV_finishget(L, t, s2v(L->top.p - 1), L->top.p - 1, slot);
@ -678,8 +688,7 @@ LUA_API int lua_gettable (lua_State *L, int idx) {
t = index2value(L, idx);
if (luaV_fastget(L, t, s2v(L->top.p - 1), slot, luaH_get)) {
setobj2s(L, L->top.p - 1, slot);
}
else
} else
luaV_finishget(L, t, s2v(L->top.p - 1), L->top.p - 1, slot);
lua_unlock(L);
return ttype(s2v(L->top.p - 1));
@ -699,8 +708,7 @@ LUA_API int lua_geti (lua_State *L, int idx, lua_Integer n) {
t = index2value(L, idx);
if (luaV_fastgeti(L, t, n, slot)) {
setobj2s(L, L->top.p, slot);
}
else {
} else {
TValue aux;
setivalue(&aux, n);
luaV_finishget(L, t, &aux, L->top.p, slot);
@ -808,8 +816,7 @@ LUA_API int lua_getiuservalue (lua_State *L, int idx, int n) {
if (n <= 0 || n > uvalue(o)->nuvalue) {
setnilvalue(s2v(L->top.p));
t = LUA_TNONE;
}
else {
} else {
setobj2s(L, L->top.p, &uvalue(o)->uv[n - 1].uv);
t = ttype(s2v(L->top.p));
}
@ -833,8 +840,7 @@ static void auxsetstr (lua_State *L, const TValue *t, const char *k) {
if (luaV_fastget(L, t, str, slot, luaH_getstr)) {
luaV_finishfastset(L, t, slot, s2v(L->top.p - 1));
L->top.p--; /* pop value */
}
else {
} else {
setsvalue2s(L, L->top.p, str); /* push 'str' (to make it a TValue) */
api_incr_top(L);
luaV_finishset(L, t, s2v(L->top.p - 1), s2v(L->top.p - 2), slot);
@ -860,8 +866,7 @@ LUA_API void lua_settable (lua_State *L, int idx) {
t = index2value(L, idx);
if (luaV_fastget(L, t, s2v(L->top.p - 2), slot, luaH_get)) {
luaV_finishfastset(L, t, slot, s2v(L->top.p - 1));
}
else
} else
luaV_finishset(L, t, s2v(L->top.p - 2), s2v(L->top.p - 1), slot);
L->top.p -= 2; /* pop index and value */
lua_unlock(L);
@ -882,8 +887,7 @@ LUA_API void lua_seti (lua_State *L, int idx, lua_Integer n) {
t = index2value(L, idx);
if (luaV_fastgeti(L, t, n, slot)) {
luaV_finishfastset(L, t, slot, s2v(L->top.p - 1));
}
else {
} else {
TValue aux;
setivalue(&aux, n);
luaV_finishset(L, t, &aux, s2v(L->top.p - 1), slot);
@ -1015,8 +1019,7 @@ LUA_API void lua_callk (lua_State *L, int nargs, int nresults,
L->ci->u.c.k = k; /* save continuation */
L->ci->u.c.ctx = ctx; /* save context */
luaD_call(L, func, nresults); /* do the call */
}
else /* no continuation or no yieldable */
} else /* no continuation or no yieldable */
luaD_callnoyield(L, func, nresults); /* just do the call */
adjustresults(L, nresults);
lua_unlock(L);
@ -1062,8 +1065,7 @@ LUA_API int lua_pcallk (lua_State *L, int nargs, int nresults, int errfunc,
if (k == NULL || !yieldable(L)) { /* no continuation or no yieldable? */
c.nresults = nresults; /* do a 'conventional' protected call */
status = luaD_pcall(L, f_call, &c, savestack(L, c.func), func);
}
else { /* prepare continuation (call is already protected by 'resume') */
} else { /* prepare continuation (call is already protected by 'resume') */
CallInfo *ci = L->ci;
ci->u.c.k = k; /* save continuation */
ci->u.c.ctx = ctx; /* save context */
@ -1169,8 +1171,7 @@ LUA_API int lua_gc (lua_State *L, int what, ...) {
if (data == 0) {
luaE_setdebt(g, 0); /* do a basic step */
luaC_step(L);
}
else { /* add 'data' to total debt */
} else { /* add 'data' to total debt */
debt = cast(l_mem, data) * 1024 + g->GCdebt;
luaE_setdebt(g, debt);
luaC_checkGC(L);
@ -1221,7 +1222,8 @@ LUA_API int lua_gc (lua_State *L, int what, ...) {
luaC_changemode(L, KGC_INC);
break;
}
default: res = -1; /* invalid option */
default:
res = -1; /* invalid option */
}
va_end(argp);
lua_unlock(L);
@ -1259,8 +1261,7 @@ LUA_API int lua_next (lua_State *L, int idx) {
more = luaH_next(L, t, L->top.p - 1);
if (more) {
api_incr_top(L);
}
else /* no more elements */
} else /* no more elements */
L->top.p -= 1; /* remove key */
lua_unlock(L);
return more;
@ -1376,7 +1377,8 @@ static const char *aux_upvalue (TValue *fi, int n, TValue **val,
name = p->upvalues[n - 1].name;
return (name == NULL) ? "(no name)" : getstr(name);
}
default: return NULL; /* not a closure */
default:
return NULL; /* not a closure */
}
}

View file

@ -58,8 +58,7 @@ static int findfield (lua_State *L, int objidx, int level) {
if (lua_rawequal(L, objidx, -1)) { /* found object? */
lua_pop(L, 1); /* remove value (but keep name) */
return 1;
}
else if (findfield(L, objidx, level - 1)) { /* try recursively */
} else if (findfield(L, objidx, level - 1)) { /* try recursively */
/* stack: lib_name, lib_table, field_name (top) */
lua_pushliteral(L, "."); /* place '.' between the two names */
lua_replace(L, -3); /* (in the slot occupied by table) */
@ -90,8 +89,7 @@ static int pushglobalfuncname (lua_State *L, lua_Debug *ar) {
lua_copy(L, -1, top + 1); /* copy name to proper place */
lua_settop(L, top + 1); /* remove table "loaded" and name copy */
return 1;
}
else {
} else {
lua_settop(L, top); /* remove function and global table */
return 0;
}
@ -102,8 +100,7 @@ static void pushfuncname (lua_State *L, lua_Debug *ar) {
if (pushglobalfuncname(L, ar)) { /* try first a global name */
lua_pushfstring(L, "function '%s'", lua_tostring(L, -1));
lua_remove(L, -2); /* remove name */
}
else if (*ar->namewhat != '\0') /* is there a name from code? */
} else if (*ar->namewhat != '\0') /* is there a name from code? */
lua_pushfstring(L, "%s '%s'", ar->namewhat, ar->name); /* use it */
else if (*ar->what == 'm') /* main? */
lua_pushliteral(L, "main chunk");
@ -147,8 +144,7 @@ LUALIB_API void luaL_traceback (lua_State *L, lua_State *L1,
lua_pushfstring(L, "\n\t...\t(skipping %d levels)", n);
luaL_addvalue(&b); /* add warning about skip */
level += n; /* and skip to last levels */
}
else {
} else {
lua_getinfo(L1, "Slnt", &ar);
if (ar.currentline <= 0)
lua_pushfstring(L, "\n\t%s: in ", ar.short_src);
@ -248,8 +244,7 @@ LUALIB_API int luaL_fileresult (lua_State *L, int stat, const char *fname) {
if (stat) {
lua_pushboolean(L, 1);
return 1;
}
else {
} else {
const char *msg;
luaL_pushfail(L);
msg = (en != 0) ? strerror(en) : "(no extra info)";
@ -415,8 +410,7 @@ LUALIB_API const char *luaL_optlstring (lua_State *L, int arg,
if (len)
*len = (def ? strlen(def) : 0);
return def;
}
else return luaL_checklstring(L, arg, len);
} else return luaL_checklstring(L, arg, len);
}
@ -672,8 +666,7 @@ LUALIB_API int luaL_ref (lua_State *L, int t) {
ref = 0; /* list is empty */
lua_pushinteger(L, 0); /* initialize as an empty list */
lua_rawseti(L, t, freelist); /* ref = t[freelist] = 0 */
}
else { /* already initialized */
} else { /* already initialized */
lua_assert(lua_isinteger(L, -1));
ref = (int)lua_tointeger(L, -1); /* ref = t[freelist] */
}
@ -681,8 +674,7 @@ LUALIB_API int luaL_ref (lua_State *L, int t) {
if (ref != 0) { /* any free element? */
lua_rawgeti(L, t, ref); /* remove it from list */
lua_rawseti(L, t, freelist); /* (t[freelist] = t[ref]) */
}
else /* no free elements */
} else /* no free elements */
ref = (int)lua_rawlen(L, t) + 1; /* get a new reference */
lua_rawseti(L, t, ref);
return ref;
@ -722,8 +714,7 @@ static const char *getF (lua_State *L, void *ud, size_t *size) {
if (lf->n > 0) { /* are there pre-read characters to be read? */
*size = lf->n; /* return them (chars already in buffer) */
lf->n = 0; /* no more pre-read characters */
}
else { /* read a block from file */
} else { /* read a block from file */
/* 'fread' can return > 0 *and* set the EOF flag. If next call to
'getF' called 'fread', it might still wait for user input.
The next check avoids this problem. */
@ -776,8 +767,7 @@ static int skipcomment (FILE *f, int *cp) {
} while (c != EOF && c != '\n');
*cp = getc(f); /* next character after comment, if present */
return 1; /* there was a comment */
}
else return 0; /* no comment */
} else return 0; /* no comment */
}
@ -790,8 +780,7 @@ LUALIB_API int luaL_loadfilex (lua_State *L, const char *filename,
if (filename == NULL) {
lua_pushliteral(L, "=stdin");
lf.f = stdin;
}
else {
} else {
lua_pushfstring(L, "@%s", filename);
errno = 0;
lf.f = fopen(filename, "r");
@ -900,8 +889,7 @@ LUALIB_API const char *luaL_tolstring (lua_State *L, int idx, size_t *len) {
if (luaL_callmeta(L, idx, "__tostring")) { /* metafield? */
if (!lua_isstring(L, -1))
luaL_error(L, "'__tostring' must return a string");
}
else {
} else {
switch (lua_type(L, idx)) {
case LUA_TNUMBER: {
if (lua_isinteger(L, idx))
@ -1024,12 +1012,12 @@ LUALIB_API const char *luaL_gsub (lua_State *L, const char *s,
static void *l_alloc(void *ud, void *ptr, size_t osize, size_t nsize) {
(void)ud; (void)osize; /* not used */
(void)ud;
(void)osize; /* not used */
if (nsize == 0) {
free(ptr);
return NULL;
}
else
} else
return realloc(ptr, nsize);
}

View file

@ -83,8 +83,7 @@ static int luaB_tonumber (lua_State *L) {
if (lua_type(L, 1) == LUA_TNUMBER) { /* already a number? */
lua_settop(L, 1); /* yes; return it */
return 1;
}
else {
} else {
size_t l;
const char *s = lua_tolstring(L, 1, &l);
if (s != NULL && lua_stringtonumber(L, s) == l + 1)
@ -92,8 +91,7 @@ static int luaB_tonumber (lua_State *L) {
/* else not a number */
luaL_checkany(L, 1); /* (but there must be some parameter) */
}
}
else {
} else {
size_t l;
const char *s;
lua_Integer n = 0; /* to avoid warnings */
@ -199,10 +197,12 @@ static int pushmode (lua_State *L, int oldmode) {
static int luaB_collectgarbage(lua_State *L) {
static const char *const opts[] = {"stop", "restart", "collect",
"count", "step", "setpause", "setstepmul",
"isrunning", "generational", "incremental", NULL};
"isrunning", "generational", "incremental", NULL
};
static const int optsnum[] = {LUA_GCSTOP, LUA_GCRESTART, LUA_GCCOLLECT,
LUA_GCCOUNT, LUA_GCSTEP, LUA_GCSETPAUSE, LUA_GCSETSTEPMUL,
LUA_GCISRUNNING, LUA_GCGEN, LUA_GCINC};
LUA_GCISRUNNING, LUA_GCGEN, LUA_GCINC
};
int o = optsnum[luaL_checkoption(L, 1, "collect", opts)];
switch (o) {
case LUA_GCCOUNT: {
@ -277,7 +277,9 @@ static int luaB_next (lua_State *L) {
static int pairscont(lua_State *L, int status, lua_KContext k) {
(void)L; (void)status; (void)k; /* unused */
(void)L;
(void)status;
(void)k; /* unused */
return 3;
}
@ -287,8 +289,7 @@ static int luaB_pairs (lua_State *L) {
lua_pushcfunction(L, luaB_next); /* will return generator, */
lua_pushvalue(L, 1); /* state, */
lua_pushnil(L); /* and initial value */
}
else {
} else {
lua_pushvalue(L, 1); /* argument 'self' to metamethod */
lua_callk(L, 1, 3, 0, pairscont); /* get 3 values from metamethod */
}
@ -328,8 +329,7 @@ static int load_aux (lua_State *L, int status, int envidx) {
lua_pop(L, 1); /* remove 'env' if not used by previous call */
}
return 1;
}
else { /* error (message is on top of the stack) */
} else { /* error (message is on top of the stack) */
luaL_pushfail(L);
lua_insert(L, -2); /* put before error message */
return 2; /* return fail plus error message */
@ -376,8 +376,7 @@ static const char *generic_reader (lua_State *L, void *ud, size_t *size) {
lua_pop(L, 1); /* pop result */
*size = 0;
return NULL;
}
else if (l_unlikely(!lua_isstring(L, -1)))
} else if (l_unlikely(!lua_isstring(L, -1)))
luaL_error(L, "reader function must return a string");
lua_replace(L, RESERVEDSLOT); /* save string in reserved slot */
return lua_tolstring(L, RESERVEDSLOT, size);
@ -393,8 +392,7 @@ static int luaB_load (lua_State *L) {
if (s != NULL) { /* loading a string? */
const char *chunkname = luaL_optstring(L, 2, s);
status = luaL_loadbufferx(L, s, l, chunkname, mode);
}
else { /* loading from a reader function */
} else { /* loading from a reader function */
const char *chunkname = luaL_optstring(L, 2, "=(load)");
luaL_checktype(L, 1, LUA_TFUNCTION);
lua_settop(L, RESERVEDSLOT); /* create reserved slot */
@ -407,7 +405,8 @@ static int luaB_load (lua_State *L) {
static int dofilecont(lua_State *L, int d1, lua_KContext d2) {
(void)d1; (void)d2; /* only to match 'lua_Kfunction' prototype */
(void)d1;
(void)d2; /* only to match 'lua_Kfunction' prototype */
return lua_gettop(L) - 1;
}
@ -440,8 +439,7 @@ static int luaB_select (lua_State *L) {
if (lua_type(L, 1) == LUA_TSTRING && *lua_tostring(L, 1) == '#') {
lua_pushinteger(L, n - 1);
return 1;
}
else {
} else {
lua_Integer i = luaL_checkinteger(L, 1);
if (i < 0) i = n + i;
else if (i > n) i = n;
@ -463,8 +461,7 @@ static int finishpcall (lua_State *L, int status, lua_KContext extra) {
lua_pushboolean(L, 0); /* first result (false) */
lua_pushvalue(L, -2); /* error message */
return 2; /* return false, msg */
}
else
} else
return lua_gettop(L) - (int)extra; /* return all results */
}

View file

@ -63,7 +63,8 @@ static int tonumeral (const expdesc *e, TValue *v) {
case VKFLT:
if (v) setfltvalue(v, e->u.nval);
return 1;
default: return 0;
default:
return 0;
}
}
@ -102,7 +103,8 @@ int luaK_exp2const (FuncState *fs, const expdesc *e, TValue *v) {
setobj(fs->ls->L, v, const2val(fs, e));
return 1;
}
default: return tonumeral(e, v);
default:
return tonumeral(e, v);
}
}
@ -207,9 +209,15 @@ int luaK_jump (FuncState *fs) {
void luaK_ret(FuncState *fs, int first, int nret) {
OpCode op;
switch (nret) {
case 0: op = OP_RETURN0; break;
case 1: op = OP_RETURN1; break;
default: op = OP_RETURN; break;
case 0:
op = OP_RETURN0;
break;
case 1:
op = OP_RETURN1;
break;
default:
op = OP_RETURN;
break;
}
luaK_codeABC(fs, op, first, nret + 1, 0);
}
@ -356,8 +364,7 @@ static void removelastlineinfo (FuncState *fs) {
if (f->lineinfo[pc] != ABSLINEINFO) { /* relative line info? */
fs->previousline -= f->lineinfo[pc]; /* correct last line saved */
fs->iwthabs--; /* undo previous increment */
}
else { /* absolute line information */
} else { /* absolute line information */
lua_assert(f->abslineinfo[fs->nabslineinfo - 1].pc == pc);
fs->nabslineinfo--; /* remove it */
fs->iwthabs = MAXIWTHABS + 1; /* force next line info to be absolute */
@ -503,8 +510,7 @@ static void freeregs (FuncState *fs, int r1, int r2) {
if (r1 > r2) {
freereg(fs, r1);
freereg(fs, r2);
}
else {
} else {
freereg(fs, r2);
freereg(fs, r1);
}
@ -692,10 +698,12 @@ static void luaK_float (FuncState *fs, int reg, lua_Number f) {
static void const2exp(TValue *v, expdesc *e) {
switch (ttypetag(v)) {
case LUA_VNUMINT:
e->k = VKINT; e->u.ival = ivalue(v);
e->k = VKINT;
e->u.ival = ivalue(v);
break;
case LUA_VNUMFLT:
e->k = VKFLT; e->u.nval = fltvalue(v);
e->k = VKFLT;
e->u.nval = fltvalue(v);
break;
case LUA_VFALSE:
e->k = VFALSE;
@ -706,10 +714,13 @@ static void const2exp (TValue *v, expdesc *e) {
case LUA_VNIL:
e->k = VNIL;
break;
case LUA_VSHRSTR: case LUA_VLNGSTR:
e->k = VKSTR; e->u.strval = tsvalue(v);
case LUA_VSHRSTR:
case LUA_VLNGSTR:
e->k = VKSTR;
e->u.strval = tsvalue(v);
break;
default: lua_assert(0);
default:
lua_assert(0);
}
}
@ -757,8 +768,7 @@ void luaK_setoneret (FuncState *fs, expdesc *e) {
lua_assert(GETARG_C(getinstruction(fs, e)) == 2);
e->k = VNONRELOC; /* result has fixed position */
e->u.info = GETARG_A(getinstruction(fs, e));
}
else if (e->k == VVARARG) {
} else if (e->k == VVARARG) {
SETARG_C(getinstruction(fs, e), 2);
e->k = VRELOC; /* can relocate its simple result */
}
@ -809,11 +819,13 @@ void luaK_dischargevars (FuncState *fs, expdesc *e) {
e->k = VRELOC;
break;
}
case VVARARG: case VCALL: {
case VVARARG:
case VCALL: {
luaK_setoneret(fs, e);
break;
}
default: break; /* there is one value available (somewhere) */
default:
break; /* there is one value available (somewhere) */
}
}
@ -1000,14 +1012,29 @@ static int luaK_exp2K (FuncState *fs, expdesc *e) {
if (!hasjumps(e)) {
int info;
switch (e->k) { /* move constants to 'k' */
case VTRUE: info = boolT(fs); break;
case VFALSE: info = boolF(fs); break;
case VNIL: info = nilK(fs); break;
case VKINT: info = luaK_intK(fs, e->u.ival); break;
case VKFLT: info = luaK_numberK(fs, e->u.nval); break;
case VKSTR: info = stringK(fs, e->u.strval); break;
case VK: info = e->u.info; break;
default: return 0; /* not a constant */
case VTRUE:
info = boolT(fs);
break;
case VFALSE:
info = boolF(fs);
break;
case VNIL:
info = nilK(fs);
break;
case VKINT:
info = luaK_intK(fs, e->u.ival);
break;
case VKFLT:
info = luaK_numberK(fs, e->u.nval);
break;
case VKSTR:
info = stringK(fs, e->u.strval);
break;
case VK:
info = e->u.info;
break;
default:
return 0; /* not a constant */
}
if (info <= MAXINDEXRK) { /* does constant fit in 'argC'? */
e->k = VK; /* make expression a 'K' expression */
@ -1074,7 +1101,8 @@ void luaK_storevar (FuncState *fs, expdesc *var, expdesc *ex) {
codeABRK(fs, OP_SETTABLE, var->u.ind.t, var->u.ind.idx, ex);
break;
}
default: lua_assert(0); /* invalid var kind to store */
default:
lua_assert(0); /* invalid var kind to store */
}
freeexp(fs, ex);
}
@ -1140,7 +1168,11 @@ void luaK_goiftrue (FuncState *fs, expdesc *e) {
pc = e->u.info; /* save jump position */
break;
}
case VK: case VKFLT: case VKINT: case VKSTR: case VTRUE: {
case VK:
case VKFLT:
case VKINT:
case VKSTR:
case VTRUE: {
pc = NO_JUMP; /* always true; do nothing */
break;
}
@ -1166,7 +1198,8 @@ void luaK_goiffalse (FuncState *fs, expdesc *e) {
pc = e->u.info; /* already jump if true */
break;
}
case VNIL: case VFALSE: {
case VNIL:
case VFALSE: {
pc = NO_JUMP; /* always false; do nothing */
break;
}
@ -1186,11 +1219,16 @@ void luaK_goiffalse (FuncState *fs, expdesc *e) {
*/
static void codenot(FuncState *fs, expdesc *e) {
switch (e->k) {
case VNIL: case VFALSE: {
case VNIL:
case VFALSE: {
e->k = VTRUE; /* true == not nil == not false */
break;
}
case VK: case VKFLT: case VKINT: case VKSTR: case VTRUE: {
case VK:
case VKFLT:
case VKINT:
case VKSTR:
case VTRUE: {
e->k = VFALSE; /* false == not "x" == not 0.5 == not 1 == not true */
break;
}
@ -1206,7 +1244,8 @@ static void codenot (FuncState *fs, expdesc *e) {
e->k = VRELOC;
break;
}
default: lua_assert(0); /* cannot happen */
default:
lua_assert(0); /* cannot happen */
}
/* interchange true and false lists */
{ int temp = e->f; e->f = e->t; e->t = temp; }
@ -1264,8 +1303,7 @@ static int isSCnumber (expdesc *e, int *pi, int *isfloat) {
if (!hasjumps(e) && fitsC(i)) {
*pi = int2sC(cast_int(i));
return 1;
}
else
} else
return 0;
}
@ -1289,19 +1327,16 @@ void luaK_indexed (FuncState *fs, expdesc *t, expdesc *k) {
t->u.ind.t = temp; /* (can't do a direct assignment; values overlap) */
t->u.ind.idx = k->u.info; /* literal short string */
t->k = VINDEXUP;
}
else {
} else {
/* register index of the table */
t->u.ind.t = (t->k == VLOCAL) ? t->u.var.ridx : t->u.info;
if (isKstr(fs, k)) {
t->u.ind.idx = k->u.info; /* literal short string */
t->k = VINDEXSTR;
}
else if (isCint(k)) {
} else if (isCint(k)) {
t->u.ind.idx = cast_int(k->u.ival); /* int. constant in proper range */
t->k = VINDEXI;
}
else {
} else {
t->u.ind.idx = luaK_exp2anyreg(fs, k); /* register */
t->k = VINDEXED;
}
@ -1316,15 +1351,22 @@ void luaK_indexed (FuncState *fs, expdesc *t, expdesc *k) {
*/
static int validop(int op, TValue *v1, TValue *v2) {
switch (op) {
case LUA_OPBAND: case LUA_OPBOR: case LUA_OPBXOR:
case LUA_OPSHL: case LUA_OPSHR: case LUA_OPBNOT: { /* conversion errors */
case LUA_OPBAND:
case LUA_OPBOR:
case LUA_OPBXOR:
case LUA_OPSHL:
case LUA_OPSHR:
case LUA_OPBNOT: { /* conversion errors */
lua_Integer i;
return (luaV_tointegerns(v1, &i, LUA_FLOORN2I) &&
luaV_tointegerns(v2, &i, LUA_FLOORN2I));
}
case LUA_OPDIV: case LUA_OPIDIV: case LUA_OPMOD: /* division by 0 */
case LUA_OPDIV:
case LUA_OPIDIV:
case LUA_OPMOD: /* division by 0 */
return (nvalue(v2) != 0);
default: return 1; /* everything else is valid */
default:
return 1; /* everything else is valid */
}
}
@ -1342,8 +1384,7 @@ static int constfolding (FuncState *fs, int op, expdesc *e1,
if (ttisinteger(&res)) {
e1->k = VKINT;
e1->u.ival = ivalue(&res);
}
else { /* folds neither NaN nor 0.0 (to avoid problems with -0.0) */
} else { /* folds neither NaN nor 0.0 (to avoid problems with -0.0) */
lua_Number n = fltvalue(&res);
if (luai_numisnan(n) || n == 0)
return 0;
@ -1480,7 +1521,9 @@ static int finishbinexpneg (FuncState *fs, expdesc *e1, expdesc *e2,
static void swapexps(expdesc *e1, expdesc *e2) {
expdesc temp = *e1; *e1 = *e2; *e2 = temp; /* swap 'e1' and 'e2' */
expdesc temp = *e1;
*e1 = *e2;
*e2 = temp; /* swap 'e1' and 'e2' */
}
@ -1559,14 +1602,12 @@ static void codeorder (FuncState *fs, BinOpr opr, expdesc *e1, expdesc *e2) {
r1 = luaK_exp2anyreg(fs, e1);
r2 = im;
op = binopr2op(opr, OPR_LT, OP_LTI);
}
else if (isSCnumber(e1, &im, &isfloat)) {
} else if (isSCnumber(e1, &im, &isfloat)) {
/* transform (A < B) to (B > A) and (A <= B) to (B >= A) */
r1 = luaK_exp2anyreg(fs, e2);
r2 = im;
op = binopr2op(opr, OPR_LT, OP_GTI);
}
else { /* regular case, compare two registers */
} else { /* regular case, compare two registers */
r1 = luaK_exp2anyreg(fs, e1);
r2 = luaK_exp2anyreg(fs, e2);
op = binopr2op(opr, OPR_LT, OP_LT);
@ -1594,12 +1635,10 @@ static void codeeq (FuncState *fs, BinOpr opr, expdesc *e1, expdesc *e2) {
if (isSCnumber(e2, &im, &isfloat)) {
op = OP_EQI;
r2 = im; /* immediate operand */
}
else if (exp2RK(fs, e2)) { /* 2nd expression is constant? */
} else if (exp2RK(fs, e2)) { /* 2nd expression is constant? */
op = OP_EQK;
r2 = e2->u.info; /* constant index */
}
else {
} else {
op = OP_EQ; /* will compare two registers */
r2 = luaK_exp2anyreg(fs, e2);
}
@ -1616,15 +1655,19 @@ void luaK_prefix (FuncState *fs, UnOpr opr, expdesc *e, int line) {
static const expdesc ef = {VKINT, {0}, NO_JUMP, NO_JUMP};
luaK_dischargevars(fs, e);
switch (opr) {
case OPR_MINUS: case OPR_BNOT: /* use 'ef' as fake 2nd operand */
case OPR_MINUS:
case OPR_BNOT: /* use 'ef' as fake 2nd operand */
if (constfolding(fs, opr + LUA_OPUNM, e, &ef))
break;
/* else */ /* FALLTHROUGH */
case OPR_LEN:
codeunexpval(fs, unopr2op(opr), e, line);
break;
case OPR_NOT: codenot(fs, e); break;
default: lua_assert(0);
case OPR_NOT:
codenot(fs, e);
break;
default:
lua_assert(0);
}
}
@ -1648,32 +1691,43 @@ void luaK_infix (FuncState *fs, BinOpr op, expdesc *v) {
luaK_exp2nextreg(fs, v); /* operand must be on the stack */
break;
}
case OPR_ADD: case OPR_SUB:
case OPR_MUL: case OPR_DIV: case OPR_IDIV:
case OPR_MOD: case OPR_POW:
case OPR_BAND: case OPR_BOR: case OPR_BXOR:
case OPR_SHL: case OPR_SHR: {
case OPR_ADD:
case OPR_SUB:
case OPR_MUL:
case OPR_DIV:
case OPR_IDIV:
case OPR_MOD:
case OPR_POW:
case OPR_BAND:
case OPR_BOR:
case OPR_BXOR:
case OPR_SHL:
case OPR_SHR: {
if (!tonumeral(v, NULL))
luaK_exp2anyreg(fs, v);
/* else keep numeral, which may be folded or used as an immediate
operand */
break;
}
case OPR_EQ: case OPR_NE: {
case OPR_EQ:
case OPR_NE: {
if (!tonumeral(v, NULL))
exp2RK(fs, v);
/* else keep numeral, which may be an immediate operand */
break;
}
case OPR_LT: case OPR_LE:
case OPR_GT: case OPR_GE: {
case OPR_LT:
case OPR_LE:
case OPR_GT:
case OPR_GE: {
int dummy, dummy2;
if (!isSCnumber(v, &dummy, &dummy2))
luaK_exp2anyreg(fs, v);
/* else keep numeral, which may be an immediate operand */
break;
}
default: lua_assert(0);
default:
lua_assert(0);
}
}
@ -1690,8 +1744,7 @@ static void codeconcat (FuncState *fs, expdesc *e1, expdesc *e2, int line) {
freeexp(fs, e2);
SETARG_A(*ie2, e1->u.info); /* correct first element ('e1') */
SETARG_B(*ie2, n + 1); /* will concatenate one more element */
}
else { /* 'e2' is not a concatenation */
} else { /* 'e2' is not a concatenation */
luaK_codeABC(fs, OP_CONCAT, e1->u.info, 2, 0); /* new concat opcode */
freeexp(fs, e2);
luaK_fixline(fs, line);
@ -1725,7 +1778,8 @@ void luaK_posfix (FuncState *fs, BinOpr opr,
codeconcat(fs, e1, e2, line);
break;
}
case OPR_ADD: case OPR_MUL: {
case OPR_ADD:
case OPR_MUL: {
codecommutative(fs, opr, e1, e2, line);
break;
}
@ -1734,11 +1788,16 @@ void luaK_posfix (FuncState *fs, BinOpr opr,
break; /* coded as (r1 + -I) */
/* ELSE */
} /* FALLTHROUGH */
case OPR_DIV: case OPR_IDIV: case OPR_MOD: case OPR_POW: {
case OPR_DIV:
case OPR_IDIV:
case OPR_MOD:
case OPR_POW: {
codearith(fs, opr, e1, e2, 0, line);
break;
}
case OPR_BAND: case OPR_BOR: case OPR_BXOR: {
case OPR_BAND:
case OPR_BOR:
case OPR_BXOR: {
codebitwise(fs, opr, e1, e2, line);
break;
}
@ -1746,11 +1805,9 @@ void luaK_posfix (FuncState *fs, BinOpr opr,
if (isSCint(e1)) {
swapexps(e1, e2);
codebini(fs, OP_SHLI, e1, e2, 1, line, TM_SHL); /* I << r2 */
}
else if (finishbinexpneg(fs, e1, e2, OP_SHRI, line, TM_SHL)) {
} else if (finishbinexpneg(fs, e1, e2, OP_SHRI, line, TM_SHL)) {
/* coded as (r1 >> -I) */;
}
else /* regular case (two registers) */
} else /* regular case (two registers) */
codebinexpval(fs, opr, e1, e2, line);
break;
}
@ -1761,20 +1818,24 @@ void luaK_posfix (FuncState *fs, BinOpr opr,
codebinexpval(fs, opr, e1, e2, line);
break;
}
case OPR_EQ: case OPR_NE: {
case OPR_EQ:
case OPR_NE: {
codeeq(fs, opr, e1, e2);
break;
}
case OPR_GT: case OPR_GE: {
case OPR_GT:
case OPR_GE: {
/* '(a > b)' <=> '(b < a)'; '(a >= b)' <=> '(b <= a)' */
swapexps(e1, e2);
opr = cast(BinOpr, (opr - OPR_GT) + OPR_LT);
} /* FALLTHROUGH */
case OPR_LT: case OPR_LE: {
case OPR_LT:
case OPR_LE: {
codeorder(fs, opr, e1, e2);
break;
}
default: lua_assert(0);
default:
lua_assert(0);
}
}
@ -1850,13 +1911,15 @@ void luaK_finish (FuncState *fs) {
Instruction *pc = &p->code[i];
lua_assert(i == 0 || isOT(*(pc - 1)) == isIT(*pc));
switch (GET_OPCODE(*pc)) {
case OP_RETURN0: case OP_RETURN1: {
case OP_RETURN0:
case OP_RETURN1: {
if (!(fs->needclose || p->is_vararg))
break; /* no extra work */
/* else use OP_RETURN to do the extra work */
SET_OPCODE(*pc, OP_RETURN);
} /* FALLTHROUGH */
case OP_RETURN: case OP_TAILCALL: {
case OP_RETURN:
case OP_TAILCALL: {
if (fs->needclose)
SETARG_k(*pc, 1); /* signal that it needs to close */
if (p->is_vararg)
@ -1868,7 +1931,8 @@ void luaK_finish (FuncState *fs) {
fixjump(fs, i, target);
break;
}
default: break;
default:
break;
}
}
}

View file

@ -45,8 +45,7 @@ static int auxresume (lua_State *L, lua_State *co, int narg) {
}
lua_xmove(co, L, nres); /* move yielded values */
return nres;
}
else {
} else {
lua_xmove(co, L, 1); /* move error message */
return -1; /* error flag */
}
@ -61,8 +60,7 @@ static int luaB_coresume (lua_State *L) {
lua_pushboolean(L, 0);
lua_insert(L, -2);
return 2; /* return false + error message */
}
else {
} else {
lua_pushboolean(L, 1);
lua_insert(L, -(r + 1));
return r + 1; /* return true + 'resume' returns */
@ -171,13 +169,13 @@ static int luaB_close (lua_State *L) {
lua_State *co = getco(L);
int status = auxstatus(L, co);
switch (status) {
case COS_DEAD: case COS_YIELD: {
case COS_DEAD:
case COS_YIELD: {
status = lua_closethread(co, L);
if (status == LUA_OK) {
lua_pushboolean(L, 1);
return 1;
}
else {
} else {
lua_pushboolean(L, 0);
lua_xmove(co, L, 1); /* move error message */
return 2;

View file

@ -95,8 +95,7 @@ static lua_State *getthread (lua_State *L, int *arg) {
if (lua_isthread(L, 1)) {
*arg = 1;
return lua_tothread(L, 1);
}
else {
} else {
*arg = 0;
return L; /* function will operate over current thread */
}
@ -157,8 +156,7 @@ static int db_getinfo (lua_State *L) {
options = lua_pushfstring(L, ">%s", options); /* add '>' to 'options' */
lua_pushvalue(L, arg + 1); /* move function to 'L1' stack */
lua_xmove(L, L1, 1);
}
else { /* stack level */
} else { /* stack level */
if (!lua_getstack(L1, (int)luaL_checkinteger(L, arg + 1), &ar)) {
luaL_pushfail(L); /* level out of range */
return 1;
@ -208,8 +206,7 @@ static int db_getlocal (lua_State *L) {
lua_pushvalue(L, arg + 1); /* push function */
lua_pushstring(L, lua_getlocal(L, NULL, nvar)); /* push local name */
return 1; /* return only name (there is no value) */
}
else { /* stack-level argument */
} else { /* stack-level argument */
lua_Debug ar;
const char *name;
int level = (int)luaL_checkinteger(L, arg + 1);
@ -222,8 +219,7 @@ static int db_getlocal (lua_State *L) {
lua_pushstring(L, name); /* push name */
lua_rotate(L, -2, 1); /* re-order */
return 2;
}
else {
} else {
luaL_pushfail(L); /* no name (nor value) */
return 1;
}
@ -368,13 +364,15 @@ static int db_sethook (lua_State *L) {
lua_State *L1 = getthread(L, &arg);
if (lua_isnoneornil(L, arg + 1)) { /* no hook? */
lua_settop(L, arg + 1);
func = NULL; mask = 0; count = 0; /* turn off hooks */
}
else {
func = NULL;
mask = 0;
count = 0; /* turn off hooks */
} else {
const char *smask = luaL_checkstring(L, arg + 2);
luaL_checktype(L, arg + 1, LUA_TFUNCTION);
count = (int)luaL_optinteger(L, arg + 3, 0);
func = hookf; mask = makemask(smask, count);
func = hookf;
mask = makemask(smask, count);
}
if (!luaL_getsubtable(L, LUA_REGISTRYINDEX, HOOKKEY)) {
/* table just created; initialize it */
@ -384,7 +382,8 @@ static int db_sethook (lua_State *L) {
lua_setmetatable(L, -2); /* metatable(hooktable) = hooktable */
}
checkstack(L, L1, 1);
lua_pushthread(L1); lua_xmove(L1, L, 1); /* key (thread) */
lua_pushthread(L1);
lua_xmove(L1, L, 1); /* key (thread) */
lua_pushvalue(L, arg + 1); /* value (hook function) */
lua_rawset(L, -3); /* hooktable[L1] = new Lua hook */
lua_sethook(L1, func, mask, count);
@ -401,13 +400,13 @@ static int db_gethook (lua_State *L) {
if (hook == NULL) { /* no hook? */
luaL_pushfail(L);
return 1;
}
else if (hook != hookf) /* external hook? */
} else if (hook != hookf) /* external hook? */
lua_pushliteral(L, "external hook");
else { /* hook table must exist */
lua_getfield(L, LUA_REGISTRYINDEX, HOOKKEY);
checkstack(L, L1, 1);
lua_pushthread(L1); lua_xmove(L1, L, 1);
lua_pushthread(L1);
lua_xmove(L1, L, 1);
lua_rawget(L, -2); /* 1st result = hooktable[L1] */
lua_remove(L, -2); /* remove hook table */
}

View file

@ -61,8 +61,7 @@ static int getbaseline (const Proto *f, int pc, int *basepc) {
if (f->sizeabslineinfo == 0 || pc < f->abslineinfo[0].pc) {
*basepc = -1; /* start from the beginning */
return f->linedefined;
}
else {
} else {
int i = cast_uint(pc) / MAXIWTHABS - 1; /* get an estimate */
/* estimate must be a lower bound of the correct base */
lua_assert(i < 0 ||
@ -167,8 +166,7 @@ LUA_API int lua_getstack (lua_State *L, int level, lua_Debug *ar) {
if (level == 0 && ci != &L->base_ci) { /* level found? */
status = 1;
ar->i_ci = ci;
}
else status = 0; /* no such level */
} else status = 0; /* no such level */
lua_unlock(L);
return status;
}
@ -207,8 +205,7 @@ const char *luaG_findlocal (lua_State *L, CallInfo *ci, int n, StkId *pos) {
if (limit - base >= n && n > 0) { /* is 'n' inside 'ci' stack? */
/* generic name for any valid slot */
name = isLua(ci) ? "(temporary)" : "(C temporary)";
}
else
} else
return NULL; /* no name */
}
if (pos)
@ -225,8 +222,7 @@ LUA_API const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n) {
name = NULL;
else /* consider live variables at function start (parameters) */
name = luaF_getlocalname(clLvalue(s2v(L->top.p - 1))->p, n, 0);
}
else { /* active function; get information through 'ar' */
} else { /* active function; get information through 'ar' */
StkId pos = NULL; /* to avoid warnings */
name = luaG_findlocal(L, ar->i_ci, n, &pos);
if (name) {
@ -260,14 +256,12 @@ static void funcinfo (lua_Debug *ar, Closure *cl) {
ar->linedefined = -1;
ar->lastlinedefined = -1;
ar->what = "C";
}
else {
} else {
const Proto *p = cl->l.p;
if (p->source) {
ar->source = getstr(p->source);
ar->srclen = tsslen(p->source);
}
else {
} else {
ar->source = "=?";
ar->srclen = LL("=?");
}
@ -291,8 +285,7 @@ static void collectvalidlines (lua_State *L, Closure *f) {
if (!LuaClosure(f)) {
setnilvalue(s2v(L->top.p));
api_incr_top(L);
}
else {
} else {
const Proto *p = f->l.p;
int currentline = p->linedefined;
Table *t = luaH_new(L); /* new table to store active lines */
@ -344,8 +337,7 @@ static int auxgetinfo (lua_State *L, const char *what, lua_Debug *ar,
if (!LuaClosure(f)) {
ar->isvararg = 1;
ar->nparams = 0;
}
else {
} else {
ar->isvararg = f->l.p->is_vararg;
ar->nparams = f->l.p->numparams;
}
@ -375,7 +367,8 @@ static int auxgetinfo (lua_State *L, const char *what, lua_Debug *ar,
case 'L':
case 'f': /* handled by lua_getinfo */
break;
default: status = 0; /* invalid option */
default:
status = 0; /* invalid option */
}
}
return status;
@ -394,8 +387,7 @@ LUA_API int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar) {
api_check(L, ttisfunction(func), "function expected");
what++; /* skip the '>' */
L->top.p--; /* pop function */
}
else {
} else {
ci = ar->i_ci;
func = s2v(ci->func.p);
lua_assert(ttisfunction(func));
@ -484,8 +476,7 @@ static const char *kname (const Proto *p, int index, const char **name) {
if (ttisstring(kvalue)) {
*name = getstr(tsvalue(kvalue));
return "constant";
}
else {
} else {
*name = "?";
return NULL;
}
@ -514,9 +505,12 @@ static const char *basicgetobjname (const Proto *p, int *ppc, int reg,
*name = upvalname(p, GETARG_B(i));
return "upvalue";
}
case OP_LOADK: return kname(p, GETARG_Bx(i), name);
case OP_LOADKX: return kname(p, GETARG_Ax(p->code[pc + 1]), name);
default: break;
case OP_LOADK:
return kname(p, GETARG_Bx(i), name);
case OP_LOADKX:
return kname(p, GETARG_Ax(p->code[pc + 1]), name);
default:
break;
}
}
return NULL; /* could not find reasonable name */
@ -595,7 +589,8 @@ static const char *getobjname (const Proto *p, int lastpc, int reg,
rkname(p, lastpc, i, name);
return "method";
}
default: break; /* go through to return NULL */
default:
break; /* go through to return NULL */
}
}
return NULL; /* could not find reasonable name */
@ -621,26 +616,55 @@ static const char *funcnamefromcode (lua_State *L, const Proto *p,
return "for iterator";
}
/* other instructions can do calls through metamethods */
case OP_SELF: case OP_GETTABUP: case OP_GETTABLE:
case OP_GETI: case OP_GETFIELD:
case OP_SELF:
case OP_GETTABUP:
case OP_GETTABLE:
case OP_GETI:
case OP_GETFIELD:
tm = TM_INDEX;
break;
case OP_SETTABUP: case OP_SETTABLE: case OP_SETI: case OP_SETFIELD:
case OP_SETTABUP:
case OP_SETTABLE:
case OP_SETI:
case OP_SETFIELD:
tm = TM_NEWINDEX;
break;
case OP_MMBIN: case OP_MMBINI: case OP_MMBINK: {
case OP_MMBIN:
case OP_MMBINI:
case OP_MMBINK: {
tm = cast(TMS, GETARG_C(i));
break;
}
case OP_UNM: tm = TM_UNM; break;
case OP_BNOT: tm = TM_BNOT; break;
case OP_LEN: tm = TM_LEN; break;
case OP_CONCAT: tm = TM_CONCAT; break;
case OP_EQ: tm = TM_EQ; break;
case OP_UNM:
tm = TM_UNM;
break;
case OP_BNOT:
tm = TM_BNOT;
break;
case OP_LEN:
tm = TM_LEN;
break;
case OP_CONCAT:
tm = TM_CONCAT;
break;
case OP_EQ:
tm = TM_EQ;
break;
/* no cases for OP_EQI and OP_EQK, as they don't call metamethods */
case OP_LT: case OP_LTI: case OP_GTI: tm = TM_LT; break;
case OP_LE: case OP_LEI: case OP_GEI: tm = TM_LE; break;
case OP_CLOSE: case OP_RETURN: tm = TM_CLOSE; break;
case OP_LT:
case OP_LTI:
case OP_GTI:
tm = TM_LT;
break;
case OP_LE:
case OP_LEI:
case OP_GEI:
tm = TM_LE;
break;
case OP_CLOSE:
case OP_RETURN:
tm = TM_CLOSE;
break;
default:
return NULL; /* cannot find a reasonable name */
}
@ -657,12 +681,10 @@ static const char *funcnamefromcall (lua_State *L, CallInfo *ci,
if (ci->callstatus & CIST_HOOKED) { /* was it called inside a hook? */
*name = "?";
return "hook";
}
else if (ci->callstatus & CIST_FIN) { /* was it called as a finalizer? */
} else if (ci->callstatus & CIST_FIN) { /* was it called as a finalizer? */
*name = "__gc";
return "metamethod"; /* report it as such */
}
else if (isLua(ci))
} else if (isLua(ci))
return funcnamefromcode(L, ci_func(ci)->p, currentpc(ci), name);
else
return NULL;
@ -817,7 +839,8 @@ const char *luaG_addinfo (lua_State *L, const char *msg, TString *src,
if (src)
luaO_chunkid(buff, getstr(src), tsslen(src));
else { /* no source available; use "?" instead */
buff[0] = '?'; buff[1] = '\0';
buff[0] = '?';
buff[1] = '\0';
}
return luaO_pushfstring(L, "%s:%d: %s", buff, line, msg);
}

View file

@ -116,15 +116,13 @@ l_noret luaD_throw (lua_State *L, int errcode) {
if (L->errorJmp) { /* thread has an error handler? */
L->errorJmp->status = errcode; /* set status */
LUAI_THROW(L, L->errorJmp); /* jump to it */
}
else { /* thread has no error handler */
} else { /* thread has no error handler */
global_State *g = G(L);
errcode = luaE_resetthread(L, errcode); /* close all upvalues */
if (g->mainthread->errorJmp) { /* main thread has a handler? */
setobjs2s(L, g->mainthread->top.p++, L->top.p - 1); /* copy error obj. */
luaD_throw(g->mainthread, errcode); /* re-throw in main thread */
}
else { /* no handler at all; abort */
} else { /* no handler at all; abort */
if (g->panic) { /* panic function? */
lua_unlock(L);
g->panic(L); /* call panic function (last chance to jump out) */
@ -249,8 +247,7 @@ int luaD_growstack (lua_State *L, int n, int raiseerror) {
if (raiseerror)
luaD_throw(L, LUA_ERRERR); /* error inside message handler */
return 0; /* if not 'raiseerror', just signal it */
}
else if (n < LUAI_MAXSTACK) { /* avoids arithmetic overflows */
} else if (n < LUAI_MAXSTACK) { /* avoids arithmetic overflows */
int newsize = 2 * size; /* tentative new size */
int needed = cast_int(L->top.p - L->stack.p) + n;
if (newsize > LUAI_MAXSTACK) /* cannot cross the limit */
@ -305,8 +302,7 @@ void luaD_shrinkstack (lua_State *L) {
if (inuse <= LUAI_MAXSTACK && stacksize(L) > max) {
int nsize = (inuse > LUAI_MAXSTACK / 2) ? LUAI_MAXSTACK : inuse * 2;
luaD_reallocstack(L, nsize, 0); /* ok if that fails */
}
else /* don't change stack */
} else /* don't change stack */
condmovestack(L, {}, {}); /* (change only for debugging) */
luaE_shrinkCI(L); /* shrink CI list */
}
@ -711,8 +707,7 @@ static void finishCcall (lua_State *L, CallInfo *ci) {
lua_assert(hastocloseCfunc(ci->nresults));
n = ci->u2.nres; /* just redo 'luaD_poscall' */
/* don't need to reset CIST_CLSRET, as it will be set again anyway */
}
else {
} else {
int status = LUA_YIELD; /* default if there were no errors */
/* must have a continuation and must be able to call it */
lua_assert(ci->u.c.k != NULL && yieldable(L));
@ -798,8 +793,7 @@ static void resume (lua_State *L, void *ud) {
ci->u.l.savedpc--;
L->top.p = firstArg; /* discard arguments */
luaV_execute(L, ci); /* just continue running Lua code */
}
else { /* 'common' yield */
} else { /* 'common' yield */
if (ci->u.c.k != NULL) { /* does it have a continuation function? */
lua_unlock(L);
n = (*ci->u.c.k)(L, LUA_YIELD, ci->u.c.ctx); /* call continuation */
@ -841,8 +835,7 @@ LUA_API int lua_resume (lua_State *L, lua_State *from, int nargs,
return resume_error(L, "cannot resume non-suspended coroutine", nargs);
else if (L->top.p - (L->ci->func.p + 1) == nargs) /* no function? */
return resume_error(L, "cannot resume dead coroutine", nargs);
}
else if (L->status != LUA_YIELD) /* ended with errors? */
} else if (L->status != LUA_YIELD) /* ended with errors? */
return resume_error(L, "cannot resume dead coroutine", nargs);
L->nCcalls = (from) ? getCcalls(from) : 0;
if (getCcalls(L) >= LUAI_MAXCCALLS)
@ -891,8 +884,7 @@ LUA_API int lua_yieldk (lua_State *L, int nresults, lua_KContext ctx,
lua_assert(!isLuacode(ci));
api_check(L, nresults == 0, "hooks cannot yield values");
api_check(L, k == NULL, "hooks cannot continue after yielding");
}
else {
} else {
if ((ci->u.c.k = k) != NULL) /* is there a continuation? */
ci->u.c.ctx = ctx; /* save context */
luaD_throw(L, LUA_YIELD);
@ -930,7 +922,8 @@ int luaD_closeprotected (lua_State *L, ptrdiff_t level, int status) {
lu_byte old_allowhooks = L->allowhook;
for (;;) { /* keep closing upvalues until no more errors */
struct CloseP pcl;
pcl.level = restorestack(L, level); pcl.status = status;
pcl.level = restorestack(L, level);
pcl.status = status;
status = luaD_rawrunprotected(L, &closepaux, &pcl);
if (l_likely(status == LUA_OK)) /* no more errors? */
return pcl.status;
@ -996,8 +989,7 @@ static void f_parser (lua_State *L, void *ud) {
if (c == LUA_SIGNATURE[0]) {
checkmode(L, p->mode, "binary");
cl = luaU_undump(L, p->z, p->name);
}
else {
} else {
checkmode(L, p->mode, "text");
cl = luaY_parser(L, p->z, &p->buff, &p->dyd, p->name, c);
}
@ -1011,10 +1003,15 @@ int luaD_protectedparser (lua_State *L, ZIO *z, const char *name,
struct SParser p;
int status;
incnny(L); /* cannot yield during parsing */
p.z = z; p.name = name; p.mode = mode;
p.dyd.actvar.arr = NULL; p.dyd.actvar.size = 0;
p.dyd.gt.arr = NULL; p.dyd.gt.size = 0;
p.dyd.label.arr = NULL; p.dyd.label.size = 0;
p.z = z;
p.name = name;
p.mode = mode;
p.dyd.actvar.arr = NULL;
p.dyd.actvar.size = 0;
p.dyd.gt.arr = NULL;
p.dyd.gt.size = 0;
p.dyd.label.arr = NULL;
p.dyd.label.size = 0;
luaZ_initbuffer(L, &p.buff);
status = luaD_pcall(L, f_parser, &p, savestack(L, L->top.p), L->errfunc);
luaZ_freebuffer(L, &p.buff);

View file

@ -124,17 +124,24 @@ static void entersweep (lua_State *L);
static GCObject **getgclist(GCObject *o) {
switch (o->tt) {
case LUA_VTABLE: return &gco2t(o)->gclist;
case LUA_VLCL: return &gco2lcl(o)->gclist;
case LUA_VCCL: return &gco2ccl(o)->gclist;
case LUA_VTHREAD: return &gco2th(o)->gclist;
case LUA_VPROTO: return &gco2p(o)->gclist;
case LUA_VTABLE:
return &gco2t(o)->gclist;
case LUA_VLCL:
return &gco2lcl(o)->gclist;
case LUA_VCCL:
return &gco2ccl(o)->gclist;
case LUA_VTHREAD:
return &gco2th(o)->gclist;
case LUA_VPROTO:
return &gco2p(o)->gclist;
case LUA_VUSERDATA: {
Udata *u = gco2u(o);
lua_assert(u->nuvalue > 0);
return &u->gclist;
}
default: lua_assert(0); return 0;
default:
lua_assert(0);
return 0;
}
}
@ -187,8 +194,7 @@ static int iscleared (global_State *g, const GCObject *o) {
else if (novariant(o->tt) == LUA_TSTRING) {
markobject(g, o); /* strings are 'values', so are never weak */
return 0;
}
else return iswhite(o);
} else return iswhite(o);
}
@ -214,8 +220,7 @@ void luaC_barrier_ (lua_State *L, GCObject *o, GCObject *v) {
lua_assert(!isold(v)); /* white object could not be old */
setage(v, G_OLD0); /* restore generational invariant */
}
}
else { /* sweep phase */
} else { /* sweep phase */
lua_assert(issweepphase(g));
if (g->gckind == KGC_INC) /* incremental mode? */
makewhite(g, o); /* mark 'o' as white to avoid other barriers */
@ -319,12 +324,17 @@ static void reallymarkobject (global_State *g, GCObject *o) {
}
/* else... */
} /* FALLTHROUGH */
case LUA_VLCL: case LUA_VCCL: case LUA_VTABLE:
case LUA_VTHREAD: case LUA_VPROTO: {
case LUA_VLCL:
case LUA_VCCL:
case LUA_VTABLE:
case LUA_VTHREAD:
case LUA_VPROTO: {
linkobjgclist(o, g->gray); /* to be visited later */
break;
}
default: lua_assert(0); break;
default:
lua_assert(0);
break;
}
}
@ -501,8 +511,7 @@ static int traverseephemeron (global_State *g, Table *h, int inv) {
hasclears = 1; /* table must be cleared */
if (valiswhite(gval(n))) /* value not marked yet? */
hasww = 1; /* white-white entry */
}
else if (valiswhite(gval(n))) { /* value not marked yet? */
} else if (valiswhite(gval(n))) { /* value not marked yet? */
marked = 1;
reallymarkobject(g, gcvalue(gval(n))); /* mark it now */
}
@ -555,8 +564,7 @@ static lu_mem traversetable (global_State *g, Table *h) {
traverseephemeron(g, h, 0);
else /* all weak */
linkgclist(h, g->allweak); /* nothing to traverse now */
}
else /* not weak */
} else /* not weak */
traversestrongtable(g, h);
return 1 + h->alimit + 2 * allocsizenode(h);
}
@ -662,13 +670,21 @@ static lu_mem propagatemark (global_State *g) {
nw2black(o);
g->gray = *getgclist(o); /* remove from 'gray' list */
switch (o->tt) {
case LUA_VTABLE: return traversetable(g, gco2t(o));
case LUA_VUSERDATA: return traverseudata(g, gco2u(o));
case LUA_VLCL: return traverseLclosure(g, gco2lcl(o));
case LUA_VCCL: return traverseCclosure(g, gco2ccl(o));
case LUA_VPROTO: return traverseproto(g, gco2p(o));
case LUA_VTHREAD: return traversethread(g, gco2th(o));
default: lua_assert(0); return 0;
case LUA_VTABLE:
return traversetable(g, gco2t(o));
case LUA_VUSERDATA:
return traverseudata(g, gco2u(o));
case LUA_VLCL:
return traverseLclosure(g, gco2lcl(o));
case LUA_VCCL:
return traverseCclosure(g, gco2ccl(o));
case LUA_VPROTO:
return traverseproto(g, gco2p(o));
case LUA_VTHREAD:
return traversethread(g, gco2th(o));
default:
lua_assert(0);
return 0;
}
}
@ -809,7 +825,8 @@ static void freeobj (lua_State *L, GCObject *o) {
luaM_freemem(L, ts, sizelstring(ts->u.lnglen));
break;
}
default: lua_assert(0);
default:
lua_assert(0);
}
}
@ -833,8 +850,7 @@ static GCObject **sweeplist (lua_State *L, GCObject **p, int countin,
if (isdeadm(ow, marked)) { /* is 'curr' dead? */
*p = curr->next; /* remove 'curr' from list */
freeobj(L, curr); /* erase 'curr' */
}
else { /* change mark to 'white' */
} else { /* change mark to 'white' */
curr->marked = cast_byte((marked & ~maskgcbits) | white);
p = &curr->next; /* go to next element */
}
@ -1028,8 +1044,7 @@ void luaC_checkfinalizer (lua_State *L, GCObject *o, Table *mt) {
makewhite(g, o); /* "sweep" object 'o' */
if (g->sweepgc == &o->next) /* should not remove 'sweepgc' object */
g->sweepgc = sweeptolive(L, g->sweepgc); /* change 'sweepgc' */
}
else
} else
correctpointers(g, o);
/* search for pointer pointing to 'o' */
for (p = &g->allgc; *p != o; p = &(*p)->next) { /* empty */ }
@ -1084,14 +1099,12 @@ static void sweep2old (lua_State *L, GCObject **p) {
lua_assert(isdead(g, curr));
*p = curr->next; /* remove 'curr' from list */
freeobj(L, curr); /* erase 'curr' */
}
else { /* all surviving objects become old */
} else { /* all surviving objects become old */
setage(curr, G_OLD);
if (curr->tt == LUA_VTHREAD) { /* threads must be watched */
lua_State *th = gco2th(curr);
linkgclist(th, g->grayagain); /* insert into 'grayagain' list */
}
else if (curr->tt == LUA_VUPVAL && upisopen(gco2upv(curr)))
} else if (curr->tt == LUA_VUPVAL && upisopen(gco2upv(curr)))
set2gray(curr); /* open upvalues are always gray */
else /* everything else is black */
nw2black(curr);
@ -1130,13 +1143,11 @@ static GCObject **sweepgen (lua_State *L, global_State *g, GCObject **p,
lua_assert(!isold(curr) && isdead(g, curr));
*p = curr->next; /* remove 'curr' from list */
freeobj(L, curr); /* erase 'curr' */
}
else { /* correct mark and age */
} else { /* correct mark and age */
if (getage(curr) == G_NEW) { /* new objects go back to white */
int marked = curr->marked & ~maskgcbits; /* erase GC bits */
curr->marked = cast_byte(marked | G_SURVIVAL | white);
}
else { /* all other objects will be old, and so keep their color */
} else { /* all other objects will be old, and so keep their color */
setage(curr, nextage[getage(curr)]);
if (getage(curr) == G_OLD1 && *pfirstold1 == NULL)
*pfirstold1 = curr; /* first OLD1 object in the list */
@ -1180,20 +1191,22 @@ static GCObject **correctgraylist (GCObject **p) {
nw2black(curr); /* make it black, for next barrier */
changeage(curr, G_TOUCHED1, G_TOUCHED2);
goto remain; /* keep it in the list and go to next element */
}
else if (curr->tt == LUA_VTHREAD) {
} else if (curr->tt == LUA_VTHREAD) {
lua_assert(isgray(curr));
goto remain; /* keep non-white threads on the list */
}
else { /* everything else is removed */
} else { /* everything else is removed */
lua_assert(isold(curr)); /* young objects should be white here */
if (getage(curr) == G_TOUCHED2) /* advance from TOUCHED2... */
changeage(curr, G_TOUCHED2, G_OLD); /* ... to OLD */
nw2black(curr); /* make object black (to be removed) */
goto remove;
}
remove: *p = *next; continue;
remain: p = next; continue;
remove:
*p = *next;
continue;
remain:
p = next;
continue;
}
return p;
}
@ -1204,11 +1217,14 @@ static GCObject **correctgraylist (GCObject **p) {
*/
static void correctgraylists(global_State *g) {
GCObject **list = correctgraylist(&g->grayagain);
*list = g->weak; g->weak = NULL;
*list = g->weak;
g->weak = NULL;
list = correctgraylist(list);
*list = g->allweak; g->allweak = NULL;
*list = g->allweak;
g->allweak = NULL;
list = correctgraylist(list);
*list = g->ephemeron; g->ephemeron = NULL;
*list = g->ephemeron;
g->ephemeron = NULL;
correctgraylist(list);
}
@ -1409,8 +1425,7 @@ static void stepgenfull (lua_State *L, global_State *g) {
if (newatomic < lastatomic + (lastatomic >> 3)) { /* good collection? */
atomic2gen(L, g); /* return to generational mode */
setminordebt(g);
}
else { /* another bad collection; stay in incremental mode */
} else { /* another bad collection; stay in incremental mode */
g->GCestimate = gettotalbytes(g); /* first estimate */
entersweep(L);
luaC_runtilstate(L, bitmask(GCSpause)); /* finish collection */
@ -1451,13 +1466,11 @@ static void genstep (lua_State *L, global_State *g) {
/* collected at least half of memory growth since last major
collection; keep doing minor collections. */
lua_assert(g->lastatomic == 0);
}
else { /* bad collection */
} else { /* bad collection */
g->lastatomic = numobjs; /* signal that last collection was bad */
setpause(g); /* do a long wait for next (major) collection */
}
}
else { /* regular case; do a minor collection */
} else { /* regular case; do a minor collection */
youngcollection(L, g);
setminordebt(g);
g->GCestimate = majorbase; /* preserve base value */
@ -1546,7 +1559,8 @@ static lu_mem atomic (lua_State *L) {
/* Clear values from weak tables, before checking finalizers */
clearbyvalues(g, g->weak, NULL);
clearbyvalues(g, g->allweak, NULL);
origweak = g->weak; origall = g->allweak;
origweak = g->weak;
origall = g->allweak;
separatetobefnz(g, 0); /* separate objects to be finalized */
work += markbeingfnz(g); /* mark objects that will be finalized */
work += propagateall(g); /* remark, to propagate 'resurrection' */
@ -1573,8 +1587,7 @@ static int sweepstep (lua_State *L, global_State *g,
g->sweepgc = sweeplist(L, g->sweepgc, GCSWEEPMAX, &count);
g->GCestimate += g->GCdebt - olddebt; /* update estimate */
return count;
}
else { /* enter next state */
} else { /* enter next state */
g->gcstate = nextstate;
g->sweepgc = nextlist;
return 0; /* no work done */
@ -1598,8 +1611,7 @@ static lu_mem singlestep (lua_State *L) {
if (g->gray == NULL) { /* no more gray objects? */
g->gcstate = GCSenteratomic; /* finish propagate phase */
work = 0;
}
else
} else
work = propagatemark(g); /* traverse one gray object */
break;
}
@ -1631,14 +1643,15 @@ static lu_mem singlestep (lua_State *L) {
if (g->tobefnz && !g->gcemergency) {
g->gcstopem = 0; /* ok collections during finalizers */
work = runafewfinalizers(L, GCFINMAX) * GCFINALIZECOST;
}
else { /* emergency mode or no more finalizers */
} else { /* emergency mode or no more finalizers */
g->gcstate = GCSpause; /* finish collection */
work = 0;
}
break;
}
default: lua_assert(0); return 0;
default:
lua_assert(0);
return 0;
}
g->gcstopem = 0;
return work;

View file

@ -394,8 +394,7 @@ static int io_lines (lua_State *L) {
lua_replace(L, 1); /* put it at index 1 */
tofile(L); /* check that it's a valid file handle */
toclose = 0; /* do not close it after iteration */
}
else { /* open a new file */
} else { /* open a new file */
const char *filename = luaL_checkstring(L, 1);
opencheck(L, filename, "r");
lua_replace(L, 1); /* put file at index 1 */
@ -407,8 +406,7 @@ static int io_lines (lua_State *L) {
lua_pushnil(L); /* control */
lua_pushvalue(L, 1); /* file is the to-be-closed variable (4th result) */
return 4;
}
else
} else
return 1;
}
@ -442,8 +440,7 @@ static int nextc (RN *rn) {
if (l_unlikely(rn->n >= L_MAXLENNUM)) { /* buffer overflow? */
rn->buff[0] = '\0'; /* invalidate result */
return 0; /* fail */
}
else {
} else {
rn->buff[rn->n++] = rn->c; /* save current char */
rn->c = l_getc(rn->f); /* read next one */
return 1;
@ -482,11 +479,13 @@ static int read_number (lua_State *L, FILE *f) {
int count = 0;
int hex = 0;
char decp[2];
rn.f = f; rn.n = 0;
rn.f = f;
rn.n = 0;
decp[0] = lua_getlocaledecpoint(); /* get decimal point from locale */
decp[1] = '.'; /* always accept a dot */
l_lockfile(rn.f);
do { rn.c = l_getc(rn.f); } while (isspace(rn.c)); /* skip spaces */
do { rn.c = l_getc(rn.f); }
while (isspace(rn.c)); /* skip spaces */
test2(&rn, "-+"); /* optional sign */
if (test2(&rn, "00")) {
if (test2(&rn, "xX")) hex = 1; /* numeral is hexadecimal */
@ -574,8 +573,7 @@ static int g_read (lua_State *L, FILE *f, int first) {
if (nargs == 0) { /* no arguments? */
success = read_line(L, f, 1);
n = first + 1; /* to return 1 result */
}
else {
} else {
/* ensure stack space for all results and for auxlib's buffer */
luaL_checkstack(L, nargs + LUA_MINSTACK, "too many arguments");
success = 1;
@ -583,8 +581,7 @@ static int g_read (lua_State *L, FILE *f, int first) {
if (lua_type(L, n) == LUA_TNUMBER) {
size_t l = (size_t)luaL_checkinteger(L, n);
success = (l == 0) ? test_eof(L, f) : read_chars(L, f, l);
}
else {
} else {
const char *p = luaL_checkstring(L, n);
if (*p == '*') p++; /* skip optional '*' (for compatibility) */
switch (*p) {
@ -674,8 +671,7 @@ static int g_write (lua_State *L, FILE *f, int arg) {
: fprintf(f, LUA_NUMBER_FMT,
(LUAI_UACNUMBER)lua_tonumber(L, arg));
status = status && (len > 0);
}
else {
} else {
size_t l;
const char *s = luaL_checklstring(L, arg, &l);
status = status && (fwrite(s, sizeof(char), l, f) == l);

View file

@ -85,8 +85,7 @@ const char *luaX_token2str (LexState *ls, int token) {
return luaO_pushfstring(ls->L, "'%c'", token);
else /* control character */
return luaO_pushfstring(ls->L, "'<\\%d>'", token);
}
else {
} else {
const char *s = luaX_tokens[token - FIRST_RESERVED];
if (token < TK_EOS) /* fixed format (symbols and reserved words)? */
return luaO_pushfstring(ls->L, "'%s'", s);
@ -98,8 +97,10 @@ const char *luaX_token2str (LexState *ls, int token) {
static const char *txtToken(LexState *ls, int token) {
switch (token) {
case TK_NAME: case TK_STRING:
case TK_FLT: case TK_INT:
case TK_NAME:
case TK_STRING:
case TK_FLT:
case TK_INT:
save(ls, '\0');
return luaO_pushfstring(ls->L, "'%s'", luaZ_buffer(ls->buff));
default:
@ -192,8 +193,7 @@ static int check_next1 (LexState *ls, int c) {
if (ls->current == c) {
next(ls);
return 1;
}
else return 0;
} else return 0;
}
@ -206,8 +206,7 @@ static int check_next2 (LexState *ls, const char *set) {
if (ls->current == set[0] || ls->current == set[1]) {
save_and_next(ls);
return 1;
}
else return 0;
} else return 0;
}
@ -247,8 +246,7 @@ static int read_numeral (LexState *ls, SemInfo *seminfo) {
if (ttisinteger(&obj)) {
seminfo->i = ivalue(&obj);
return TK_INT;
}
else {
} else {
lua_assert(ttisfloat(&obj));
seminfo->r = fltvalue(&obj);
return TK_FLT;
@ -298,7 +296,8 @@ static void read_long_string (LexState *ls, SemInfo *seminfo, size_t sep) {
}
break;
}
case '\n': case '\r': {
case '\n':
case '\r': {
save(ls, '\n');
inclinenumber(ls);
if (!seminfo) luaZ_resetbuffer(ls->buff); /* avoid wasting space */
@ -309,7 +308,8 @@ static void read_long_string (LexState *ls, SemInfo *seminfo, size_t sep) {
else next(ls);
}
}
} endloop:
}
endloop:
if (seminfo)
seminfo->ts = luaX_newstring(ls, luaZ_buffer(ls->buff) + sep,
luaZ_bufflen(ls->buff) - 2 * sep);
@ -394,20 +394,45 @@ static void read_string (LexState *ls, int del, SemInfo *seminfo) {
int c; /* final character to be saved */
save_and_next(ls); /* keep '\\' for error messages */
switch (ls->current) {
case 'a': c = '\a'; goto read_save;
case 'b': c = '\b'; goto read_save;
case 'f': c = '\f'; goto read_save;
case 'n': c = '\n'; goto read_save;
case 'r': c = '\r'; goto read_save;
case 't': c = '\t'; goto read_save;
case 'v': c = '\v'; goto read_save;
case 'x': c = readhexaesc(ls); goto read_save;
case 'u': utf8esc(ls); goto no_save;
case '\n': case '\r':
inclinenumber(ls); c = '\n'; goto only_save;
case '\\': case '\"': case '\'':
c = ls->current; goto read_save;
case EOZ: goto no_save; /* will raise an error next loop */
case 'a':
c = '\a';
goto read_save;
case 'b':
c = '\b';
goto read_save;
case 'f':
c = '\f';
goto read_save;
case 'n':
c = '\n';
goto read_save;
case 'r':
c = '\r';
goto read_save;
case 't':
c = '\t';
goto read_save;
case 'v':
c = '\v';
goto read_save;
case 'x':
c = readhexaesc(ls);
goto read_save;
case 'u':
utf8esc(ls);
goto no_save;
case '\n':
case '\r':
inclinenumber(ls);
c = '\n';
goto only_save;
case '\\':
case '\"':
case '\'':
c = ls->current;
goto read_save;
case EOZ:
goto no_save; /* will raise an error next loop */
case 'z': { /* zap following span of spaces */
luaZ_buffremove(ls->buff, 1); /* remove '\\' */
next(ls); /* skip the 'z' */
@ -430,7 +455,8 @@ static void read_string (LexState *ls, int del, SemInfo *seminfo) {
luaZ_buffremove(ls->buff, 1); /* remove '\\' */
save(ls, c);
/* go through */
no_save: break;
no_save:
break;
}
default:
save_and_next(ls);
@ -446,11 +472,15 @@ static int llex (LexState *ls, SemInfo *seminfo) {
luaZ_resetbuffer(ls->buff);
for (;;) {
switch (ls->current) {
case '\n': case '\r': { /* line breaks */
case '\n':
case '\r': { /* line breaks */
inclinenumber(ls);
break;
}
case ' ': case '\f': case '\t': case '\v': { /* spaces */
case ' ':
case '\f':
case '\t':
case '\v': { /* spaces */
next(ls);
break;
}
@ -478,8 +508,7 @@ static int llex (LexState *ls, SemInfo *seminfo) {
if (sep >= 2) {
read_long_string(ls, seminfo, sep);
return TK_STRING;
}
else if (sep == 0) /* '[=...' missing second bracket? */
} else if (sep == 0) /* '[=...' missing second bracket? */
lexerror(ls, "invalid long string delimiter", TK_STRING);
return '[';
}
@ -515,7 +544,8 @@ static int llex (LexState *ls, SemInfo *seminfo) {
if (check_next1(ls, ':')) return TK_DBCOLON; /* '::' */
else return ':';
}
case '"': case '\'': { /* short literal strings */
case '"':
case '\'': { /* short literal strings */
read_string(ls, ls->current, seminfo);
return TK_STRING;
}
@ -525,12 +555,19 @@ static int llex (LexState *ls, SemInfo *seminfo) {
if (check_next1(ls, '.'))
return TK_DOTS; /* '...' */
else return TK_CONCAT; /* '..' */
}
else if (!lisdigit(ls->current)) return '.';
} else if (!lisdigit(ls->current)) return '.';
else return read_numeral(ls, seminfo);
}
case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9': {
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9': {
return read_numeral(ls, seminfo);
}
case EOZ: {
@ -550,8 +587,7 @@ static int llex (LexState *ls, SemInfo *seminfo) {
else {
return TK_NAME;
}
}
else { /* single-char tokens ('+', '*', '%', '{', '}', ...) */
} else { /* single-char tokens ('+', '*', '%', '{', '}', ...) */
int c = ls->current;
next(ls);
return c;
@ -567,8 +603,7 @@ void luaX_next (LexState *ls) {
if (ls->lookahead.token != TK_EOS) { /* is there a look-ahead token? */
ls->t = ls->lookahead; /* use this one */
ls->lookahead.token = TK_EOS; /* and discharge it */
}
else
} else
ls->t.token = llex(ls, &ls->t.seminfo); /* read next token */
}

View file

@ -31,8 +31,7 @@ static int math_abs (lua_State *L) {
lua_Integer n = lua_tointeger(L, 1);
if (n < 0) n = (lua_Integer)(0u - (lua_Unsigned)n);
lua_pushinteger(L, n);
}
else
} else
lua_pushnumber(L, l_mathop(fabs)(luaL_checknumber(L, 1)));
return 1;
}
@ -120,11 +119,9 @@ static int math_fmod (lua_State *L) {
if ((lua_Unsigned)d + 1u <= 1u) { /* special cases: -1 or 0 */
luaL_argcheck(L, d != 0, 2, "zero");
lua_pushinteger(L, 0); /* avoid overflow with 0x80000... / -1 */
}
else
} else
lua_pushinteger(L, lua_tointeger(L, 1) % d);
}
else
} else
lua_pushnumber(L, l_mathop(fmod)(luaL_checknumber(L, 1),
luaL_checknumber(L, 2)));
return 1;
@ -140,8 +137,7 @@ static int math_modf (lua_State *L) {
if (lua_isinteger(L, 1)) {
lua_settop(L, 1); /* number is its own integer part */
lua_pushnumber(L, 0); /* no fractional part */
}
else {
} else {
lua_Number n = luaL_checknumber(L, 1);
/* integer part (rounds toward zero) */
lua_Number ip = (n < 0) ? l_mathop(ceil)(n) : l_mathop(floor)(n);
@ -595,7 +591,8 @@ static int math_random (lua_State *L) {
up = luaL_checkinteger(L, 2);
break;
}
default: return luaL_error(L, "wrong number of arguments");
default:
return luaL_error(L, "wrong number of arguments");
}
/* random integer in the interval [low, up] */
luaL_argcheck(L, low <= up, 1, "interval is empty");
@ -636,8 +633,7 @@ static int math_randomseed (lua_State *L) {
RanState *state = (RanState *)lua_touserdata(L, lua_upvalueindex(1));
if (lua_isnone(L, 1)) {
randseed(L, state);
}
else {
} else {
lua_Integer n1 = luaL_checkinteger(L, 1);
lua_Integer n2 = luaL_optinteger(L, 2, 0);
setseed(L, state->s, n1, n2);

View file

@ -104,8 +104,7 @@ void *luaM_growaux_ (lua_State *L, void *block, int nelems, int *psize,
if (l_unlikely(size >= limit)) /* cannot grow even a little? */
luaG_runerror(L, "too many %s (limit is %d)", what, limit);
size = limit; /* still have at least one free place */
}
else {
} else {
size *= 2;
if (size < MINSIZEARRAY)
size = MINSIZEARRAY; /* minimum size */
@ -165,8 +164,7 @@ static void *tryagain (lua_State *L, void *block,
if (cantryagain(g)) {
luaC_fullgc(L, 1); /* try to free some memory... */
return callfrealloc(g, block, osize, nsize); /* try again */
}
else return NULL; /* cannot run an emergency collection */
} else return NULL; /* cannot run an emergency collection */
}

View file

@ -234,14 +234,16 @@ static void lsys_unloadlib (void *lib) {
static void *lsys_load(lua_State *L, const char *path, int seeglb) {
(void)(path); (void)(seeglb); /* not used */
(void)(path);
(void)(seeglb); /* not used */
lua_pushliteral(L, DLMSG);
return NULL;
}
static lua_CFunction lsys_sym(lua_State *L, void *lib, const char *sym) {
(void)(lib); (void)(sym); /* not used */
(void)(lib);
(void)(sym); /* not used */
lua_pushliteral(L, DLMSG);
return NULL;
}
@ -388,8 +390,7 @@ static int lookforfunc (lua_State *L, const char *path, const char *sym) {
if (*sym == '*') { /* loading only library (no function)? */
lua_pushboolean(L, 1); /* return 'true' */
return 0; /* no errors */
}
else {
} else {
lua_CFunction f = lsys_sym(L, reg, sym);
if (f == NULL)
return ERRFUNC; /* unable to find function */
@ -526,8 +527,7 @@ static int checkload (lua_State *L, int stat, const char *filename) {
if (l_likely(stat)) { /* module loaded successfully? */
lua_pushstring(L, filename); /* will be 2nd argument to module */
return 2; /* return open function and file name */
}
else
} else
return luaL_error(L, "error loading module '%s' from file '%s':\n\t%s",
lua_tostring(L, 1), filename, lua_tostring(L, -1));
}
@ -604,8 +604,7 @@ static int searcher_preload (lua_State *L) {
if (lua_getfield(L, -1, name) == LUA_TNIL) { /* not found? */
lua_pushfstring(L, "no field package.preload['%s']", name);
return 1;
}
else {
} else {
lua_pushliteral(L, ":preload:");
return 2;
}
@ -636,8 +635,7 @@ static void findloader (lua_State *L, const char *name) {
else if (lua_isstring(L, -2)) { /* searcher returned error message? */
lua_pop(L, 1); /* remove extra return */
luaL_addvalue(&msg); /* concatenate error message */
}
else { /* no error message */
} else { /* no error message */
lua_pop(L, 2); /* remove both returns */
luaL_buffsub(&msg, 2); /* remove prefix */
}

View file

@ -53,19 +53,33 @@ int luaO_ceillog2 (unsigned int x) {
static lua_Integer intarith(lua_State *L, int op, lua_Integer v1,
lua_Integer v2) {
switch (op) {
case LUA_OPADD: return intop(+, v1, v2);
case LUA_OPSUB:return intop(-, v1, v2);
case LUA_OPMUL:return intop(*, v1, v2);
case LUA_OPMOD: return luaV_mod(L, v1, v2);
case LUA_OPIDIV: return luaV_idiv(L, v1, v2);
case LUA_OPBAND: return intop(&, v1, v2);
case LUA_OPBOR: return intop(|, v1, v2);
case LUA_OPBXOR: return intop(^, v1, v2);
case LUA_OPSHL: return luaV_shiftl(v1, v2);
case LUA_OPSHR: return luaV_shiftr(v1, v2);
case LUA_OPUNM: return intop(-, 0, v1);
case LUA_OPBNOT: return intop(^, ~l_castS2U(0), v1);
default: lua_assert(0); return 0;
case LUA_OPADD:
return intop(+, v1, v2);
case LUA_OPSUB:
return intop(-, v1, v2);
case LUA_OPMUL:
return intop(*, v1, v2);
case LUA_OPMOD:
return luaV_mod(L, v1, v2);
case LUA_OPIDIV:
return luaV_idiv(L, v1, v2);
case LUA_OPBAND:
return intop(&, v1, v2);
case LUA_OPBOR:
return intop( |, v1, v2);
case LUA_OPBXOR:
return intop(^, v1, v2);
case LUA_OPSHL:
return luaV_shiftl(v1, v2);
case LUA_OPSHR:
return luaV_shiftr(v1, v2);
case LUA_OPUNM:
return intop(-, 0, v1);
case LUA_OPBNOT:
return intop(^, ~l_castS2U(0), v1);
default:
lua_assert(0);
return 0;
}
}
@ -73,15 +87,25 @@ static lua_Integer intarith (lua_State *L, int op, lua_Integer v1,
static lua_Number numarith(lua_State *L, int op, lua_Number v1,
lua_Number v2) {
switch (op) {
case LUA_OPADD: return luai_numadd(L, v1, v2);
case LUA_OPSUB: return luai_numsub(L, v1, v2);
case LUA_OPMUL: return luai_nummul(L, v1, v2);
case LUA_OPDIV: return luai_numdiv(L, v1, v2);
case LUA_OPPOW: return luai_numpow(L, v1, v2);
case LUA_OPIDIV: return luai_numidiv(L, v1, v2);
case LUA_OPUNM: return luai_numunm(L, v1);
case LUA_OPMOD: return luaV_modf(L, v1, v2);
default: lua_assert(0); return 0;
case LUA_OPADD:
return luai_numadd(L, v1, v2);
case LUA_OPSUB:
return luai_numsub(L, v1, v2);
case LUA_OPMUL:
return luai_nummul(L, v1, v2);
case LUA_OPDIV:
return luai_numdiv(L, v1, v2);
case LUA_OPPOW:
return luai_numpow(L, v1, v2);
case LUA_OPIDIV:
return luai_numidiv(L, v1, v2);
case LUA_OPUNM:
return luai_numunm(L, v1);
case LUA_OPMOD:
return luaV_modf(L, v1, v2);
default:
lua_assert(0);
return 0;
}
}
@ -89,35 +113,38 @@ static lua_Number numarith (lua_State *L, int op, lua_Number v1,
int luaO_rawarith(lua_State *L, int op, const TValue *p1, const TValue *p2,
TValue *res) {
switch (op) {
case LUA_OPBAND: case LUA_OPBOR: case LUA_OPBXOR:
case LUA_OPSHL: case LUA_OPSHR:
case LUA_OPBAND:
case LUA_OPBOR:
case LUA_OPBXOR:
case LUA_OPSHL:
case LUA_OPSHR:
case LUA_OPBNOT: { /* operate only on integers */
lua_Integer i1; lua_Integer i2;
lua_Integer i1;
lua_Integer i2;
if (tointegerns(p1, &i1) && tointegerns(p2, &i2)) {
setivalue(res, intarith(L, op, i1, i2));
return 1;
} else return 0; /* fail */
}
else return 0; /* fail */
}
case LUA_OPDIV: case LUA_OPPOW: { /* operate only on floats */
lua_Number n1; lua_Number n2;
case LUA_OPDIV:
case LUA_OPPOW: { /* operate only on floats */
lua_Number n1;
lua_Number n2;
if (tonumberns(p1, n1) && tonumberns(p2, n2)) {
setfltvalue(res, numarith(L, op, n1, n2));
return 1;
}
else return 0; /* fail */
} else return 0; /* fail */
}
default: { /* other operations */
lua_Number n1; lua_Number n2;
lua_Number n1;
lua_Number n2;
if (ttisinteger(p1) && ttisinteger(p2)) {
setivalue(res, intarith(L, op, ivalue(p1), ivalue(p2)));
return 1;
}
else if (tonumberns(p1, n1) && tonumberns(p2, n2)) {
} else if (tonumberns(p1, n1) && tonumberns(p2, n2)) {
setfltvalue(res, numarith(L, op, n1, n2));
return 1;
}
else return 0; /* fail */
} else return 0; /* fail */
}
}
}
@ -179,16 +206,14 @@ static lua_Number lua_strx2number (const char *s, char **endptr) {
if (*s == dot) {
if (hasdot) break; /* second dot? stop loop */
else hasdot = 1;
}
else if (lisxdigit(cast_uchar(*s))) {
} else if (lisxdigit(cast_uchar(*s))) {
if (sigdig == 0 && *s == '0') /* non-significant digit (zero)? */
nosigdig++;
else if (++sigdig <= MAXSIGDIG) /* can read it without overflow? */
r = (r * l_mathop(16.0)) + luaO_hexavalue(*s);
else e++; /* too many digits; ignore, but still count for exponent */
if (hasdot) e--; /* decimal digit? correct exponent */
}
else break; /* neither a dot nor a digit */
} else break; /* neither a dot nor a digit */
}
if (nosigdig + sigdig == 0) /* no digits? */
return l_mathop(0.0); /* invalid format */
@ -286,8 +311,7 @@ static const char *l_str2int (const char *s, lua_Integer *result) {
a = a * 16 + luaO_hexavalue(*s);
empty = 0;
}
}
else { /* decimal */
} else { /* decimal */
for (; lisdigit(cast_uchar(*s)); s++) {
int d = *s - '0';
if (a >= MAXBY10 && (a > MAXBY10 || d > MAXLASTD + neg)) /* overflow? */
@ -306,15 +330,14 @@ static const char *l_str2int (const char *s, lua_Integer *result) {
size_t luaO_str2num(const char *s, TValue *o) {
lua_Integer i; lua_Number n;
lua_Integer i;
lua_Number n;
const char *e;
if ((e = l_str2int(s, &i)) != NULL) { /* try as an integer */
setivalue(o, i);
}
else if ((e = l_str2d(s, &n)) != NULL) { /* else try as a float */
} else if ((e = l_str2d(s, &n)) != NULL) { /* else try as a float */
setfltvalue(o, n);
}
else
} else
return 0; /* conversion failed */
return (e - s) + 1; /* success; return string size */
}
@ -436,7 +459,8 @@ static void clearbuff (BuffFS *buff) {
** space, empty it. 'sz' must fit in an empty buffer.
*/
static char *getbuff(BuffFS *buff, int sz) {
lua_assert(buff->blen <= BUFVFS); lua_assert(sz <= BUFVFS);
lua_assert(buff->blen <= BUFVFS);
lua_assert(sz <= BUFVFS);
if (sz > BUFVFS - buff->blen) /* not enough space? */
clearbuff(buff);
return buff->space + buff->blen;
@ -455,8 +479,7 @@ static void addstr2buff (BuffFS *buff, const char *str, size_t slen) {
char *bf = getbuff(buff, cast_int(slen));
memcpy(bf, str, slen); /* add string to buffer */
addsize(buff, cast_int(slen));
}
else { /* string larger than buffer */
} else { /* string larger than buffer */
clearbuff(buff); /* string comes after buffer's content */
pushstr(buff, str, slen); /* push string */
}
@ -573,8 +596,7 @@ void luaO_chunkid (char *out, const char *source, size_t srclen) {
addstr(out, source + 1, bufflen - 1);
*out = '\0';
}
}
else if (*source == '@') { /* file name */
} else if (*source == '@') { /* file name */
if (srclen <= bufflen) /* small enough? */
memcpy(out, source + 1, srclen * sizeof(char));
else { /* add '...' before rest of name */
@ -582,15 +604,13 @@ void luaO_chunkid (char *out, const char *source, size_t srclen) {
bufflen -= LL(RETS);
memcpy(out, source + 1 + srclen - bufflen, bufflen * sizeof(char));
}
}
else { /* string; format as [string "source"] */
} else { /* string; format as [string "source"] */
const char *nl = strchr(source, '\n'); /* find first new line (if any) */
addstr(out, PRE, LL(PRE)); /* add prefix */
bufflen -= LL(PRE RETS POS) + 1; /* save space for prefix+suffix+'\0' */
if (srclen < bufflen && nl == NULL) { /* small one-line source? */
addstr(out, source, srclen); /* keep it */
}
else {
} else {
if (nl != NULL) srclen = nl - source; /* stop at first newline */
if (srclen > bufflen) srclen = bufflen;
addstr(out, source, srclen);

View file

@ -260,8 +260,7 @@ static int getfield (lua_State *L, const char *key, int d, int delta) {
else if (l_unlikely(d < 0)) /* absent field; no default? */
return luaL_error(L, "field '%s' missing in date table", key);
res = d;
}
else {
} else {
if (!(res >= 0 ? res - delta <= INT_MAX : INT_MIN + delta <= res))
return luaL_error(L, "field '%s' is out-of-bound", key);
res -= delta;
@ -310,8 +309,7 @@ static int os_date (lua_State *L) {
if (*s == '!') { /* UTC? */
stm = l_gmtime(&t, &tmr);
s++; /* skip '!' */
}
else
} else
stm = l_localtime(&t, &tmr);
if (stm == NULL) /* invalid date? */
return luaL_error(L,
@ -319,8 +317,7 @@ static int os_date (lua_State *L) {
if (strcmp(s, "*t") == 0) {
lua_createtable(L, 0, 9); /* 9 = number of fields */
setallfields(L, stm);
}
else {
} else {
char cc[4]; /* buffer for individual conversion specifiers */
luaL_Buffer b;
cc[0] = '%';
@ -381,9 +378,11 @@ static int os_difftime (lua_State *L) {
static int os_setlocale(lua_State *L) {
static const int cat[] = {LC_ALL, LC_COLLATE, LC_CTYPE, LC_MONETARY,
LC_NUMERIC, LC_TIME};
LC_NUMERIC, LC_TIME
};
static const char *const catnames[] = {"all", "collate", "ctype", "monetary",
"numeric", "time", NULL};
"numeric", "time", NULL
};
const char *l = luaL_optstring(L, 1, NULL);
int op = luaL_checkoption(L, 2, "all", catnames);
lua_pushstring(L, setlocale(cat[op], l));

View file

@ -96,8 +96,7 @@ static int testnext (LexState *ls, int c) {
if (ls->t.token == c) {
luaX_next(ls);
return 1;
}
else return 0;
} else return 0;
}
@ -369,8 +368,7 @@ static int newupvalue (FuncState *fs, TString *name, expdesc *v) {
up->idx = v->u.var.ridx;
up->kind = getlocalvardesc(prev, v->u.var.vidx)->vd.kind;
lua_assert(eqstr(name, getlocalvardesc(prev, v->u.var.vidx)->vd.name));
}
else {
} else {
up->instack = 0;
up->idx = cast_byte(v->u.info);
up->kind = prev->f->upvalues[v->u.info].kind;
@ -440,8 +438,7 @@ static void singlevaraux (FuncState *fs, TString *n, expdesc *var, int base) {
if (v >= 0) { /* found? */
if (v == VLOCAL && !base)
markupval(fs, var->u.var.vidx); /* local will be used as an upval */
}
else { /* not found as local at current level; try upvalues */
} else { /* not found as local at current level; try upvalues */
int idx = searchupvalue(fs, n); /* try existing upvalues */
if (idx < 0) { /* not found? */
singlevaraux(fs->prev, n, var, 0); /* try upper levels */
@ -487,8 +484,7 @@ static void adjust_assign (LexState *ls, int nvars, int nexps, expdesc *e) {
if (extra < 0)
extra = 0;
luaK_setreturns(fs, e, extra); /* last exp. provides the difference */
}
else {
} else {
if (e->k != VVOID) /* at least one expression? */
luaK_exp2nextreg(fs, e); /* close last expression */
if (needed > 0) /* missing values? */
@ -590,8 +586,7 @@ static int solvegotos (LexState *ls, Labeldesc *lb) {
if (eqstr(gl->arr[i].name, lb->name)) {
needsclose |= gl->arr[i].close;
solvegoto(ls, i, lb); /* will remove 'i' from the list */
}
else
} else
i++;
}
return needsclose;
@ -660,8 +655,7 @@ static l_noret undefgoto (LexState *ls, Labeldesc *gt) {
if (eqstr(gt->name, luaS_newliteral(ls->L, "break"))) {
msg = "break outside loop at line %d";
msg = luaO_pushfstring(ls->L, msg, gt->line);
}
else {
} else {
msg = "no visible label '%s' for <goto> at line %d";
msg = luaO_pushfstring(ls->L, msg, getstr(gt->name), gt->line);
}
@ -787,11 +781,15 @@ static void close_func (LexState *ls) {
*/
static int block_follow(LexState *ls, int withuntil) {
switch (ls->t.token) {
case TK_ELSE: case TK_ELSEIF:
case TK_END: case TK_EOS:
case TK_ELSE:
case TK_ELSEIF:
case TK_END:
case TK_EOS:
return 1;
case TK_UNTIL: return withuntil;
default: return 0;
case TK_UNTIL:
return withuntil;
default:
return 0;
}
}
@ -852,8 +850,7 @@ static void recfield (LexState *ls, ConsControl *cc) {
if (ls->t.token == TK_NAME) {
checklimit(fs, cc->nh, MAX_INT, "items in a constructor");
codename(ls, &key);
}
else /* ls->t.token == '[' */
} else /* ls->t.token == '[' */
yindex(ls, &key);
cc->nh++;
checknext(ls, '=');
@ -883,8 +880,7 @@ static void lastlistfield (FuncState *fs, ConsControl *cc) {
luaK_setmultret(fs, &cc->v);
luaK_setlist(fs, cc->t->u.info, cc->na, LUA_MULTRET);
cc->na--; /* do not count last expression (unknown number of elements) */
}
else {
} else {
if (cc->v.k != VVOID)
luaK_exp2nextreg(fs, &cc->v);
luaK_setlist(fs, cc->t->u.info, cc->na, cc->tostore);
@ -975,7 +971,8 @@ static void parlist (LexState *ls) {
isvararg = 1;
break;
}
default: luaX_syntaxerror(ls, "<name> or '...' expected");
default:
luaX_syntaxerror(ls, "<name> or '...' expected");
}
} while (!isvararg && testnext(ls, ','));
}
@ -1126,12 +1123,15 @@ static void suffixedexp (LexState *ls, expdesc *v) {
funcargs(ls, v);
break;
}
case '(': case TK_STRING: case '{': { /* funcargs */
case '(':
case TK_STRING:
case '{': { /* funcargs */
luaK_exp2nextreg(fs, v);
funcargs(ls, v);
break;
}
default: return;
default:
return;
}
}
}
@ -1194,39 +1194,66 @@ static void simpleexp (LexState *ls, expdesc *v) {
static UnOpr getunopr(int op) {
switch (op) {
case TK_NOT: return OPR_NOT;
case '-': return OPR_MINUS;
case '~': return OPR_BNOT;
case '#': return OPR_LEN;
default: return OPR_NOUNOPR;
case TK_NOT:
return OPR_NOT;
case '-':
return OPR_MINUS;
case '~':
return OPR_BNOT;
case '#':
return OPR_LEN;
default:
return OPR_NOUNOPR;
}
}
static BinOpr getbinopr(int op) {
switch (op) {
case '+': return OPR_ADD;
case '-': return OPR_SUB;
case '*': return OPR_MUL;
case '%': return OPR_MOD;
case '^': return OPR_POW;
case '/': return OPR_DIV;
case TK_IDIV: return OPR_IDIV;
case '&': return OPR_BAND;
case '|': return OPR_BOR;
case '~': return OPR_BXOR;
case TK_SHL: return OPR_SHL;
case TK_SHR: return OPR_SHR;
case TK_CONCAT: return OPR_CONCAT;
case TK_NE: return OPR_NE;
case TK_EQ: return OPR_EQ;
case '<': return OPR_LT;
case TK_LE: return OPR_LE;
case '>': return OPR_GT;
case TK_GE: return OPR_GE;
case TK_AND: return OPR_AND;
case TK_OR: return OPR_OR;
default: return OPR_NOBINOPR;
case '+':
return OPR_ADD;
case '-':
return OPR_SUB;
case '*':
return OPR_MUL;
case '%':
return OPR_MOD;
case '^':
return OPR_POW;
case '/':
return OPR_DIV;
case TK_IDIV:
return OPR_IDIV;
case '&':
return OPR_BAND;
case '|':
return OPR_BOR;
case '~':
return OPR_BXOR;
case TK_SHL:
return OPR_SHL;
case TK_SHR:
return OPR_SHR;
case TK_CONCAT:
return OPR_CONCAT;
case TK_NE:
return OPR_NE;
case TK_EQ:
return OPR_EQ;
case '<':
return OPR_LT;
case TK_LE:
return OPR_LE;
case '>':
return OPR_GT;
case TK_GE:
return OPR_GE;
case TK_AND:
return OPR_AND;
case TK_OR:
return OPR_OR;
default:
return OPR_NOBINOPR;
}
}
@ -1267,8 +1294,7 @@ static BinOpr subexpr (LexState *ls, expdesc *v, int limit) {
luaX_next(ls); /* skip operator */
subexpr(ls, v, UNARY_PRIORITY);
luaK_prefix(ls->fs, uop, v, line);
}
else simpleexp(ls, v);
} else simpleexp(ls, v);
/* expand while operators have priorities higher than 'limit' */
op = getbinopr(ls->t.token);
while (op != OPR_NOBINOPR && priority[op].left > limit) {
@ -1340,8 +1366,7 @@ static void check_conflict (LexState *ls, struct LHS_assign *lh, expdesc *v) {
lh->v.k = VINDEXSTR;
lh->v.u.ind.t = extra; /* assignment will use safe copy */
}
}
else { /* table is a register */
} else { /* table is a register */
if (v->k == VLOCAL && lh->v.u.ind.t == v->u.var.ridx) {
conflict = 1; /* table is the local being assigned now */
lh->v.u.ind.t = extra; /* assignment will use safe copy */
@ -1385,8 +1410,7 @@ static void restassign (LexState *ls, struct LHS_assign *lh, int nvars) {
enterlevel(ls); /* control recursion depth */
restassign(ls, &nv, nvars + 1);
leavelevel(ls);
}
else { /* restassign -> '=' explist */
} else { /* restassign -> '=' explist */
int nexps;
checknext(ls, '=');
nexps = explist(ls, &e);
@ -1626,9 +1650,15 @@ static void forstat (LexState *ls, int line) {
luaX_next(ls); /* skip 'for' */
varname = str_checkname(ls); /* first variable name */
switch (ls->t.token) {
case '=': fornum(ls, varname, line); break;
case ',': case TK_IN: forlist(ls, varname); break;
default: luaX_syntaxerror(ls, "'=' or 'in' expected");
case '=':
fornum(ls, varname, line);
break;
case ',':
case TK_IN:
forlist(ls, varname);
break;
default:
luaX_syntaxerror(ls, "'=' or 'in' expected");
}
check_match(ls, TK_END, TK_FOR, line);
leaveblock(fs); /* loop scope ('break' jumps to this point) */
@ -1654,11 +1684,9 @@ static void test_then_block (LexState *ls, int *escapelist) {
if (block_follow(ls, 0)) { /* jump is the entire block? */
leaveblock(fs);
return; /* and that is it */
}
else /* must skip over 'then' part if condition is false */
} else /* must skip over 'then' part if condition is false */
jf = luaK_jump(fs);
}
else { /* regular case (not a break) */
} else { /* regular case (not a break) */
luaK_goiftrue(ls->fs, &v); /* skip over block if condition is false */
enterblock(fs, &bl, 0);
jf = v.f;
@ -1756,8 +1784,7 @@ static void localstat (LexState *ls) {
var->vd.kind = RDKCTC; /* variable is a compile-time constant */
adjustlocalvars(ls, nvars - 1); /* exclude last variable */
fs->nactvar++; /* but count it */
}
else {
} else {
adjust_assign(ls, nvars, nexps, &e);
adjustlocalvars(ls, nvars);
}
@ -1800,8 +1827,7 @@ static void exprstat (LexState *ls) {
if (ls->t.token == '=' || ls->t.token == ',') { /* stat -> assignment ? */
v.prev = NULL;
restassign(ls, &v, 1);
}
else { /* stat -> func */
} else { /* stat -> func */
Instruction *inst;
check_condition(ls, v.v.k == VCALL, "syntax error");
inst = &getinstruction(fs, &v.v);
@ -1827,8 +1853,7 @@ static void retstat (LexState *ls) {
lua_assert(GETARG_A(getinstruction(fs, &e)) == luaY_nvarstack(fs));
}
nret = LUA_MULTRET; /* return all values */
}
else {
} else {
if (nret == 1) /* only one single value? */
first = luaK_exp2anyreg(fs, &e); /* can use original slot */
else { /* values must go to the top of the stack */

View file

@ -97,7 +97,8 @@ void luaE_setdebt (global_State *g, l_mem debt) {
LUA_API int lua_setcstacklimit(lua_State *L, unsigned int limit) {
UNUSED(L); UNUSED(limit);
UNUSED(L);
UNUSED(limit);
return LUAI_MAXCCALLS; /* warning?? */
}
@ -178,7 +179,8 @@ LUAI_FUNC void luaE_incCstack (lua_State *L) {
static void stack_init(lua_State *L1, lua_State *L) {
int i; CallInfo *ci;
int i;
CallInfo *ci;
/* initialize stack array */
L1->stack.p = luaM_newvector(L, BASIC_STACK_SIZE + EXTRA_STACK, StackValue);
L1->tbclist.p = L1->stack.p;

View file

@ -93,8 +93,7 @@ void luaS_resize (lua_State *L, int nsize) {
if (nsize < osize) /* was it shrinking table? */
tablerehash(tb->hash, nsize, osize); /* restore to original size */
/* leave table as it was */
}
else { /* allocation succeeded */
} else { /* allocation succeeded */
tb->hash = newvect;
tb->size = nsize;
if (nsize > osize)

View file

@ -161,7 +161,8 @@ static int str_rep (lua_State *L) {
luaL_Buffer b;
char *p = luaL_buffinitsize(L, &b, totallen);
while (n-- > 1) { /* first n-1 copies (followed by separator) */
memcpy(p, s, l * sizeof(char)); p += l;
memcpy(p, s, l * sizeof(char));
p += l;
if (lsep > 0) { /* empty 'memcpy' is not that cheap */
memcpy(p, sep, lsep * sizeof(char));
p += lsep;
@ -265,8 +266,7 @@ static int tonum (lua_State *L, int arg) {
if (lua_type(L, arg) == LUA_TNUMBER) { /* already a number? */
lua_pushvalue(L, arg);
return 1;
}
else { /* check whether it is a numerical string */
} else { /* check whether it is a numerical string */
size_t len;
const char *s = lua_tolstring(L, arg, &len);
return (s != NULL && lua_stringtonumber(L, s) == len + 1);
@ -427,18 +427,41 @@ static const char *classend (MatchState *ms, const char *p) {
static int match_class(int c, int cl) {
int res;
switch (tolower(cl)) {
case 'a' : res = isalpha(c); break;
case 'c' : res = iscntrl(c); break;
case 'd' : res = isdigit(c); break;
case 'g' : res = isgraph(c); break;
case 'l' : res = islower(c); break;
case 'p' : res = ispunct(c); break;
case 's' : res = isspace(c); break;
case 'u' : res = isupper(c); break;
case 'w' : res = isalnum(c); break;
case 'x' : res = isxdigit(c); break;
case 'z' : res = (c == 0); break; /* deprecated option */
default: return (cl == c);
case 'a' :
res = isalpha(c);
break;
case 'c' :
res = iscntrl(c);
break;
case 'd' :
res = isdigit(c);
break;
case 'g' :
res = isgraph(c);
break;
case 'l' :
res = islower(c);
break;
case 'p' :
res = ispunct(c);
break;
case 's' :
res = isspace(c);
break;
case 'u' :
res = isupper(c);
break;
case 'w' :
res = isalnum(c);
break;
case 'x' :
res = isxdigit(c);
break;
case 'z' :
res = (c == 0);
break; /* deprecated option */
default:
return (cl == c);
}
return (islower(cl) ? res : !res);
}
@ -455,13 +478,11 @@ static int matchbracketclass (int c, const char *p, const char *ec) {
p++;
if (match_class(c, uchar(*p)))
return sig;
}
else if ((*(p+1) == '-') && (p+2 < ec)) {
} else if ((*(p + 1) == '-') && (p + 2 < ec)) {
p += 2;
if (uchar(*(p - 2)) <= c && c <= uchar(*p))
return sig;
}
else if (uchar(*p) == c) return sig;
} else if (uchar(*p) == c) return sig;
}
return !sig;
}
@ -474,10 +495,14 @@ static int singlematch (MatchState *ms, const char *s, const char *p,
else {
int c = uchar(*s);
switch (*p) {
case '.': return 1; /* matches any char */
case L_ESC: return match_class(c, uchar(*(p+1)));
case '[': return matchbracketclass(c, p, ep-1);
default: return (uchar(*p) == c);
case '.':
return 1; /* matches any char */
case L_ESC:
return match_class(c, uchar(*(p + 1)));
case '[':
return matchbracketclass(c, p, ep - 1);
default:
return (uchar(*p) == c);
}
}
}
@ -495,8 +520,7 @@ static const char *matchbalance (MatchState *ms, const char *s,
while (++s < ms->src_end) {
if (*s == e) {
if (--cont == 0) return s + 1;
}
else if (*s == b) cont++;
} else if (*s == b) cont++;
}
}
return NULL; /* string ends out of balance */
@ -595,12 +619,14 @@ static const char *match (MatchState *ms, const char *s, const char *p) {
case 'b': { /* balanced string? */
s = matchbalance(ms, s, p + 2);
if (s != NULL) {
p += 4; goto init; /* return match(ms, s, p + 4); */
p += 4;
goto init; /* return match(ms, s, p + 4); */
} /* else fail (s == NULL) */
break;
}
case 'f': { /* frontier? */
const char *ep; char previous;
const char *ep;
char previous;
p += 2;
if (l_unlikely(*p != '['))
luaL_error(ms->L, "missing '[' after '%%f' in pattern");
@ -608,42 +634,53 @@ static const char *match (MatchState *ms, const char *s, const char *p) {
previous = (s == ms->src_init) ? '\0' : *(s - 1);
if (!matchbracketclass(uchar(previous), p, ep - 1) &&
matchbracketclass(uchar(*s), p, ep - 1)) {
p = ep; goto init; /* return match(ms, s, ep); */
p = ep;
goto init; /* return match(ms, s, ep); */
}
s = NULL; /* match failed */
break;
}
case '0': case '1': case '2': case '3':
case '4': case '5': case '6': case '7':
case '8': case '9': { /* capture results (%0-%9)? */
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9': { /* capture results (%0-%9)? */
s = match_capture(ms, s, uchar(*(p + 1)));
if (s != NULL) {
p += 2; goto init; /* return match(ms, s, p + 2) */
p += 2;
goto init; /* return match(ms, s, p + 2) */
}
break;
}
default: goto dflt;
default:
goto dflt;
}
break;
}
default: dflt: { /* pattern class plus optional suffix */
default:
dflt: { /* pattern class plus optional suffix */
const char *ep = classend(ms, p); /* points to optional suffix */
/* does not match at least once? */
if (!singlematch(ms, s, p, ep)) {
if (*ep == '*' || *ep == '?' || *ep == '-') { /* accept empty? */
p = ep + 1; goto init; /* return match(ms, s, ep + 1); */
}
else /* '+' or no suffix */
p = ep + 1;
goto init; /* return match(ms, s, ep + 1); */
} else /* '+' or no suffix */
s = NULL; /* fail */
}
else { /* matched once */
} else { /* matched once */
switch (*ep) { /* handle optional suffix */
case '?': { /* optional */
const char *res;
if ((res = match(ms, s + 1, ep + 1)) != NULL)
s = res;
else {
p = ep + 1; goto init; /* else return match(ms, s, ep + 1); */
p = ep + 1;
goto init; /* else return match(ms, s, ep + 1); */
}
break;
}
@ -657,7 +694,9 @@ static const char *match (MatchState *ms, const char *s, const char *p) {
s = min_expand(ms, s, p, ep);
break;
default: /* no suffix */
s++; p = ep; goto init; /* return match(ms, s + 1, ep); */
s++;
p = ep;
goto init; /* return match(ms, s + 1, ep); */
}
}
break;
@ -706,8 +745,7 @@ static size_t get_onecapture (MatchState *ms, int i, const char *s,
luaL_error(ms->L, "invalid capture index %%%d", i + 1);
*cap = s;
return e - s;
}
else {
} else {
ptrdiff_t capl = ms->capture[i].len;
*cap = ms->capture[i].init;
if (l_unlikely(capl == CAP_UNFINISHED))
@ -788,13 +826,13 @@ static int str_find_aux (lua_State *L, int find) {
lua_pushinteger(L, (s2 - s) + lp);
return 2;
}
}
else {
} else {
MatchState ms;
const char *s1 = s + init;
int anchor = (*p == '^');
if (anchor) {
p++; lp--; /* skip anchor character */
p++;
lp--; /* skip anchor character */
}
prepstate(&ms, L, s, ls, p, lp);
do {
@ -805,8 +843,7 @@ static int str_find_aux (lua_State *L, int find) {
lua_pushinteger(L, (s1 - s) + 1); /* start */
lua_pushinteger(L, res - s); /* end */
return push_captures(&ms, NULL, 0) + 2;
}
else
} else
return push_captures(&ms, s1, res);
}
} while (s1++ < ms.src_end && !anchor);
@ -862,7 +899,9 @@ static int gmatch (lua_State *L) {
if (init > ls) /* start after string's end? */
init = ls + 1; /* avoid overflows in 's + init' */
prepstate(&gm->ms, L, s, ls, p, lp);
gm->src = s + init; gm->p = p; gm->lastmatch = NULL;
gm->src = s + init;
gm->p = p;
gm->lastmatch = NULL;
lua_pushcclosure(L, gmatch_aux, 3);
return 1;
}
@ -888,8 +927,7 @@ static void add_s (MatchState *ms, luaL_Buffer *b, const char *s,
luaL_addvalue(b); /* add position to accumulated result */
else
luaL_addlstring(b, cap, resl);
}
else
} else
luaL_error(L, "invalid use of '%c' in replacement string", L_ESC);
l -= p + 1 - news;
news = p + 1;
@ -928,8 +966,7 @@ static int add_value (MatchState *ms, luaL_Buffer *b, const char *s,
lua_pop(L, 1); /* remove value */
luaL_addlstring(b, s, e - s); /* keep original text */
return 0; /* no changes */
}
else if (l_unlikely(!lua_isstring(L, -1)))
} else if (l_unlikely(!lua_isstring(L, -1)))
return luaL_error(L, "invalid replacement value (a %s)",
luaL_typename(L, -1));
else {
@ -956,7 +993,8 @@ static int str_gsub (lua_State *L) {
"string/function/table");
luaL_buffinit(L, &b);
if (anchor) {
p++; lp--; /* skip anchor character */
p++;
lp--; /* skip anchor character */
}
prepstate(&ms, L, src, srcl, p, lp);
while (n < max_s) {
@ -966,8 +1004,7 @@ static int str_gsub (lua_State *L) {
n++;
changed = add_value(&ms, &b, src, e, tr) | changed;
src = lastmatch = e;
}
else if (src < ms.src_end) /* otherwise, skip one character */
} else if (src < ms.src_end) /* otherwise, skip one character */
luaL_addchar(&b, *src++);
else break; /* end of subject */
if (anchor) break;
@ -1028,8 +1065,7 @@ static int num2straux (char *buff, int sz, lua_Number x) {
else if (x == 0) { /* can be -0... */
/* create "0" or "-0" followed by exponent */
return l_sprintf(buff, sz, LUA_NUMBER_FMT "x0p+0", (LUAI_UACNUMBER)x);
}
else {
} else {
int e;
lua_Number m = l_mathop(frexp)(x, &e); /* 'x' fraction and exponent */
int n = 0; /* character count */
@ -1037,7 +1073,8 @@ static int num2straux (char *buff, int sz, lua_Number x) {
buff[n++] = '-'; /* add sign */
m = -m; /* make it positive */
}
buff[n++] = '0'; buff[n++] = 'x'; /* add "0x" */
buff[n++] = '0';
buff[n++] = 'x'; /* add "0x" */
m = adddigit(buff, n++, m * (1 << L_NBFD)); /* add first digit */
e -= L_NBFD; /* this digit goes before the radix point */
if (m > 0) { /* more digits? */
@ -1060,8 +1097,7 @@ static int lua_number2strx (lua_State *L, char *buff, int sz,
int i;
for (i = 0; i < n; i++)
buff[i] = toupper(uchar(buff[i]));
}
else if (l_unlikely(fmt[SIZELENMOD] != 'a'))
} else if (l_unlikely(fmt[SIZELENMOD] != 'a'))
return luaL_error(L, "modifiers for format '%%a'/'%%A' not implemented");
return n;
}
@ -1125,16 +1161,14 @@ static void addquoted (luaL_Buffer *b, const char *s, size_t len) {
if (*s == '"' || *s == '\\' || *s == '\n') {
luaL_addchar(b, '\\');
luaL_addchar(b, *s);
}
else if (iscntrl(uchar(*s))) {
} else if (iscntrl(uchar(*s))) {
char buff[10];
if (!isdigit(uchar(*(s + 1))))
l_sprintf(buff, sizeof(buff), "\\%d", (int)uchar(*s));
else
l_sprintf(buff, sizeof(buff), "\\%03d", (int)uchar(*s));
luaL_addstring(b, buff);
}
else
} else
luaL_addchar(b, *s);
s++;
}
@ -1195,7 +1229,8 @@ static void addliteral (lua_State *L, luaL_Buffer *b, int arg) {
luaL_addsize(b, nb);
break;
}
case LUA_TNIL: case LUA_TBOOLEAN: {
case LUA_TNIL:
case LUA_TBOOLEAN: {
luaL_tolstring(L, arg, NULL);
luaL_addvalue(b);
break;
@ -1298,13 +1333,16 @@ static int str_format (lua_State *L) {
nb = l_sprintf(buff, maxitem, form, (int)luaL_checkinteger(L, arg));
break;
}
case 'd': case 'i':
case 'd':
case 'i':
flags = L_FMTFLAGSI;
goto intcase;
case 'u':
flags = L_FMTFLAGSU;
goto intcase;
case 'o': case 'x': case 'X':
case 'o':
case 'x':
case 'X':
flags = L_FMTFLAGSX;
intcase: {
lua_Integer n = luaL_checkinteger(L, arg);
@ -1313,7 +1351,8 @@ static int str_format (lua_State *L) {
nb = l_sprintf(buff, maxitem, form, (LUAI_UACINT)n);
break;
}
case 'a': case 'A':
case 'a':
case 'A':
checkformat(L, form, L_FMTFLAGSF, 1);
addlenmod(form, LUA_NUMBER_FRMLEN);
nb = lua_number2strx(L, buff, maxitem, form,
@ -1323,7 +1362,10 @@ static int str_format (lua_State *L) {
maxitem = MAX_ITEMF; /* extra space for '%f' */
buff = luaL_prepbuffsize(&b, maxitem);
/* FALLTHROUGH */
case 'e': case 'E': case 'g': case 'G': {
case 'e':
case 'E':
case 'g':
case 'G': {
lua_Number n = luaL_checknumber(L, arg);
checkformat(L, form, L_FMTFLAGSF, 1);
addlenmod(form, LUA_NUMBER_FRMLEN);
@ -1357,8 +1399,7 @@ static int str_format (lua_State *L) {
if (strchr(form, '.') == NULL && l >= 100) {
/* no precision and string is too long to be formatted */
luaL_addvalue(&b); /* keep entire string */
}
else { /* format the string into 'buff' */
} else { /* format the string into 'buff' */
nb = l_sprintf(buff, maxitem, form, s);
lua_pop(L, 1); /* remove result from 'luaL_tolstring' */
}
@ -1491,39 +1532,81 @@ static KOption getoption (Header *h, const char **fmt, int *size) {
int opt = *((*fmt)++);
*size = 0; /* default */
switch (opt) {
case 'b': *size = sizeof(char); return Kint;
case 'B': *size = sizeof(char); return Kuint;
case 'h': *size = sizeof(short); return Kint;
case 'H': *size = sizeof(short); return Kuint;
case 'l': *size = sizeof(long); return Kint;
case 'L': *size = sizeof(long); return Kuint;
case 'j': *size = sizeof(lua_Integer); return Kint;
case 'J': *size = sizeof(lua_Integer); return Kuint;
case 'T': *size = sizeof(size_t); return Kuint;
case 'f': *size = sizeof(float); return Kfloat;
case 'n': *size = sizeof(lua_Number); return Knumber;
case 'd': *size = sizeof(double); return Kdouble;
case 'i': *size = getnumlimit(h, fmt, sizeof(int)); return Kint;
case 'I': *size = getnumlimit(h, fmt, sizeof(int)); return Kuint;
case 's': *size = getnumlimit(h, fmt, sizeof(size_t)); return Kstring;
case 'b':
*size = sizeof(char);
return Kint;
case 'B':
*size = sizeof(char);
return Kuint;
case 'h':
*size = sizeof(short);
return Kint;
case 'H':
*size = sizeof(short);
return Kuint;
case 'l':
*size = sizeof(long);
return Kint;
case 'L':
*size = sizeof(long);
return Kuint;
case 'j':
*size = sizeof(lua_Integer);
return Kint;
case 'J':
*size = sizeof(lua_Integer);
return Kuint;
case 'T':
*size = sizeof(size_t);
return Kuint;
case 'f':
*size = sizeof(float);
return Kfloat;
case 'n':
*size = sizeof(lua_Number);
return Knumber;
case 'd':
*size = sizeof(double);
return Kdouble;
case 'i':
*size = getnumlimit(h, fmt, sizeof(int));
return Kint;
case 'I':
*size = getnumlimit(h, fmt, sizeof(int));
return Kuint;
case 's':
*size = getnumlimit(h, fmt, sizeof(size_t));
return Kstring;
case 'c':
*size = getnum(fmt, -1);
if (l_unlikely(*size == -1))
luaL_error(h->L, "missing size for format option 'c'");
return Kchar;
case 'z': return Kzstr;
case 'x': *size = 1; return Kpadding;
case 'X': return Kpaddalign;
case ' ': break;
case '<': h->islittle = 1; break;
case '>': h->islittle = 0; break;
case '=': h->islittle = nativeendian.little; break;
case 'z':
return Kzstr;
case 'x':
*size = 1;
return Kpadding;
case 'X':
return Kpaddalign;
case ' ':
break;
case '<':
h->islittle = 1;
break;
case '>':
h->islittle = 0;
break;
case '=':
h->islittle = nativeendian.little;
break;
case '!': {
const int maxalign = offsetof(struct cD, u);
h->maxalign = getnumlimit(h, fmt, maxalign);
break;
}
default: luaL_error(h->L, "invalid format option '%c'", opt);
default:
luaL_error(h->L, "invalid format option '%c'", opt);
}
return Knop;
}
@ -1686,8 +1769,10 @@ static int str_pack (lua_State *L) {
totalsize += len + 1;
break;
}
case Kpadding: luaL_addchar(&b, LUAL_PACKPADBYTE); /* FALLTHROUGH */
case Kpaddalign: case Knop:
case Kpadding:
luaL_addchar(&b, LUAL_PACKPADBYTE); /* FALLTHROUGH */
case Kpaddalign:
case Knop:
arg--; /* undo increment */
break;
}
@ -1739,8 +1824,7 @@ static lua_Integer unpackint (lua_State *L, const char *str,
lua_Unsigned mask = (lua_Unsigned)1 << (size * NB - 1);
res = ((res ^ mask) - mask); /* do sign extension */
}
}
else if (size > SZINT) { /* must check unread bytes */
} else if (size > SZINT) { /* must check unread bytes */
int mask = (!issigned || (lua_Integer)res >= 0) ? 0 : MC;
for (i = limit; i < size; i++) {
if (l_unlikely((unsigned char)str[islittle ? i : size - 1 - i] != mask))
@ -1814,7 +1898,9 @@ static int str_unpack (lua_State *L) {
pos += len + 1; /* skip string plus final '\0' */
break;
}
case Kpaddalign: case Kpadding: case Knop:
case Kpaddalign:
case Kpadding:
case Knop:
n--; /* undo increment */
break;
}

View file

@ -92,7 +92,8 @@
static const Node dummynode_ = {
{ {NULL}, LUA_VEMPTY, /* value's value and type */
LUA_VNIL, 0, {NULL}} /* key type, next, and key value */
LUA_VNIL, 0, {NULL}
} /* key type, next, and key value */
};
@ -135,8 +136,7 @@ static int l_hashfloat (lua_Number n) {
if (!lua_numbertointeger(n, &ni)) { /* is 'n' inf/-inf/NaN? */
lua_assert(luai_numisnan(n) || l_mathop(fabs)(n) == cast_num(HUGE_VAL));
return 0;
}
else { /* normal case */
} else { /* normal case */
unsigned int u = cast_uint(i) + cast_uint(ni);
return cast_int(u <= cast_uint(INT_MAX) ? u : ~u);
}
@ -218,7 +218,9 @@ static int equalkey (const TValue *k1, const Node *n2, int deadok) {
!(deadok && keyisdead(n2) && iscollectable(k1)))
return 0; /* cannot be same key */
switch (keytt(n2)) {
case LUA_VNIL: case LUA_VFALSE: case LUA_VTRUE:
case LUA_VNIL:
case LUA_VFALSE:
case LUA_VTRUE:
return 1;
case LUA_VNUMINT:
return (ivalue(k1) == keyival(n2));
@ -415,8 +417,7 @@ static int countint (lua_Integer key, unsigned int *nums) {
if (k != 0) { /* is 'key' an appropriate array index? */
nums[luaO_ceillog2(k)]++; /* count as such */
return 1;
}
else
} else
return 0;
}
@ -482,8 +483,7 @@ static void setnodevector (lua_State *L, Table *t, unsigned int size) {
t->node = cast(Node *, dummynode); /* use common 'dummynode' */
t->lsizenode = 0;
t->lastfree = NULL; /* signal that it is using dummy node */
}
else {
} else {
int i;
int lsize = luaO_ceillog2(size);
if (lsize > MAXHBITS || (1u << lsize) > MAXHSIZE)
@ -674,8 +674,7 @@ static void luaH_newkey (lua_State *L, Table *t, const TValue *key,
if (luaV_flttointeger(f, &k, F2Ieq)) { /* does key fit in an integer? */
setivalue(&aux, k);
key = &aux; /* insert it as an integer */
}
else if (l_unlikely(luai_numisnan(f)))
} else if (l_unlikely(luai_numisnan(f)))
luaG_runerror(L, "table index is NaN");
}
if (ttisnil(value))
@ -703,8 +702,7 @@ static void luaH_newkey (lua_State *L, Table *t, const TValue *key,
gnext(mp) = 0; /* now 'mp' is free */
}
setempty(gval(mp));
}
else { /* colliding node is in its own main position */
} else { /* colliding node is in its own main position */
/* new node will go into free position */
if (gnext(mp) != 0)
gnext(f) = cast_int((mp + gnext(mp)) - f); /* chain new position */
@ -750,8 +748,7 @@ const TValue *luaH_getint (Table *t, lua_Integer key) {
(((l_castS2U(key) - 1u) & ~(alimit - 1u)) < alimit)) {
t->alimit = cast_uint(key); /* probably '#t' is here now */
return &t->array[key - 1];
}
else { /* key is not in the array part; check the hash */
} else { /* key is not in the array part; check the hash */
Node *n = hashint(t, key);
for (;;) { /* check whether 'key' is somewhere in the chain */
if (keyisinteger(n) && keyival(n) == key)
@ -802,9 +799,12 @@ const TValue *luaH_getstr (Table *t, TString *key) {
*/
const TValue *luaH_get(Table *t, const TValue *key) {
switch (ttypetag(key)) {
case LUA_VSHRSTR: return luaH_getshortstr(t, tsvalue(key));
case LUA_VNUMINT: return luaH_getint(t, ivalue(key));
case LUA_VNIL: return &absentkey;
case LUA_VSHRSTR:
return luaH_getshortstr(t, tsvalue(key));
case LUA_VNUMINT:
return luaH_getint(t, ivalue(key));
case LUA_VNIL:
return &absentkey;
case LUA_VNUMFLT: {
lua_Integer k;
if (luaV_flttointeger(fltvalue(key), &k, F2Ieq)) /* integral index? */
@ -848,8 +848,7 @@ void luaH_setint (lua_State *L, Table *t, lua_Integer key, TValue *value) {
TValue k;
setivalue(&k, key);
luaH_newkey(L, t, &k, value);
}
else
} else
setobj2t(L, cast(TValue *, p), value);
}
@ -946,8 +945,7 @@ lua_Unsigned luaH_getn (Table *t) {
setnorealasize(t); /* now 'alimit' is not the real size */
}
return limit - 1;
}
else { /* must search for a boundary in [0, limit] */
} else { /* must search for a boundary in [0, limit] */
unsigned int boundary = binsearch(t->array, 0, limit);
/* can this boundary represent the real size of the array? */
if (ispow2realasize(t) && boundary > luaH_realasize(t) / 2) {

View file

@ -51,8 +51,7 @@ static void checktab (lua_State *L, int arg, int what) {
(!(what & TAB_W) || checkfield(L, "__newindex", ++n)) &&
(!(what & TAB_L) || checkfield(L, "__len", ++n))) {
lua_pop(L, n); /* pop metatable and tested metamethods */
}
else
} else
luaL_checktype(L, arg, LUA_TTABLE); /* force an error */
}
}
@ -131,8 +130,7 @@ static int tmove (lua_State *L) {
lua_geti(L, 1, f + i);
lua_seti(L, tt, t + i);
}
}
else {
} else {
for (i = n - 1; i >= 0; i--) {
lua_geti(L, 1, f + i);
lua_seti(L, tt, t + i);
@ -384,8 +382,7 @@ static void auxsort (lua_State *L, IdxT lo, IdxT up,
auxsort(L, lo, p - 1, rnd); /* call recursively for lower interval */
n = p - lo; /* size of smaller interval */
lo = p + 1; /* tail call for [p + 1 .. up] (upper interval) */
}
else {
} else {
auxsort(L, p + 1, up, rnd); /* call recursively for upper interval */
n = up - p; /* size of smaller interval */
up = p - 1; /* tail call for [lo .. p - 1] (lower interval) */

View file

@ -63,8 +63,7 @@ const TValue *luaT_gettm (Table *events, TMS event, TString *ename) {
if (notm(tm)) { /* no tag method? */
events->flags |= cast_byte(1u << event); /* cache this fact */
return NULL;
}
else return tm;
} else return tm;
}
@ -149,8 +148,12 @@ void luaT_trybinTM (lua_State *L, const TValue *p1, const TValue *p2,
StkId res, TMS event) {
if (l_unlikely(!callbinTM(L, p1, p2, res, event))) {
switch (event) {
case TM_BAND: case TM_BOR: case TM_BXOR:
case TM_SHL: case TM_SHR: case TM_BNOT: {
case TM_BAND:
case TM_BOR:
case TM_BXOR:
case TM_SHL:
case TM_SHR:
case TM_BNOT: {
if (ttisnumber(p1) && ttisnumber(p2))
luaG_tointerror(L, p1, p2);
else
@ -220,16 +223,16 @@ int luaT_callorderTM (lua_State *L, const TValue *p1, const TValue *p2,
int luaT_callorderiTM(lua_State *L, const TValue *p1, int v2,
int flip, int isfloat, TMS event) {
TValue aux; const TValue *p2;
TValue aux;
const TValue *p2;
if (isfloat) {
setfltvalue(&aux, cast_num(v2));
}
else
} else
setivalue(&aux, v2);
if (flip) { /* arguments were exchanged? */
p2 = p1; p1 = &aux; /* correct them */
}
else
p2 = p1;
p1 = &aux; /* correct them */
} else
p2 = &aux;
return luaT_callorderTM(L, p1, p2, event);
}

View file

@ -221,8 +221,7 @@ static int dolibrary (lua_State *L, char *globname) {
if (modname == NULL) { /* no explicit name? */
modname = globname; /* module name is equal to global name */
suffix = strchr(modname, *LUA_IGMARK); /* look for a suffix mark */
}
else {
} else {
*modname = '\0'; /* global name ends here */
modname++; /* module name starts after the '=' */
}
@ -289,8 +288,7 @@ static int collectargs (char **argv, int *first) {
if (argv[0] != NULL) { /* is there a program name? */
if (argv[0][0]) /* not empty? */
progname = argv[0]; /* save it */
}
else { /* no program name */
} else { /* no program name */
*first = -1;
return 0;
}
@ -351,7 +349,8 @@ static int runargs (lua_State *L, char **argv, int n) {
int option = argv[i][1];
lua_assert(argv[i][0] == '-'); /* already checked */
switch (option) {
case 'e': case 'l': {
case 'e':
case 'l': {
int status;
char *extra = argv[i] + 2; /* both options need an argument */
if (*extra == '\0') extra = argv[++i];
@ -535,8 +534,7 @@ static int addreturn (lua_State *L) {
lua_remove(L, -2); /* remove modified line */
if (line[0] != '\0') /* non empty? */
lua_saveline(L, line); /* keep history */
}
else
} else
lua_pop(L, 2); /* pop result from 'luaL_loadbuffer' and modified line */
return status;
}
@ -660,8 +658,7 @@ static int pmain (lua_State *L) {
if (lua_stdin_is_tty()) { /* running in interactive mode? */
print_version();
doREPL(L); /* do read-eval-print loop */
}
else dofile(L, NULL); /* executes stdin as a file */
} else dofile(L, NULL); /* executes stdin as a file */
}
lua_pushboolean(L, 1); /* signal no errors */
return 1;

View file

@ -39,20 +39,17 @@ static const char* output=Output; /* actual output file name */
static const char *progname = PROGNAME; /* actual program name */
static TString **tmname;
static void fatal(const char* message)
{
static void fatal(const char *message) {
fprintf(stderr, "%s: %s\n", progname, message);
exit(EXIT_FAILURE);
}
static void cannot(const char* what)
{
static void cannot(const char *what) {
fprintf(stderr, "%s: cannot %s %s: %s\n", progname, what, output, strerror(errno));
exit(EXIT_FAILURE);
}
static void usage(const char* message)
{
static void usage(const char *message) {
if (*message == '-')
fprintf(stderr, "%s: unrecognized option '%s'\n", progname, message);
else
@ -73,33 +70,27 @@ static void usage(const char* message)
#define IS(s) (strcmp(argv[i],s)==0)
static int doargs(int argc, char* argv[])
{
static int doargs(int argc, char *argv[]) {
int i;
int version = 0;
if (argv[0] != NULL && *argv[0] != 0) progname = argv[0];
for (i=1; i<argc; i++)
{
for (i = 1; i < argc; i++) {
if (*argv[i] != '-') /* end of options; keep it */
break;
else if (IS("--")) /* end of options; skip it */
{
else if (IS("--")) { /* end of options; skip it */
++i;
if (version) ++version;
break;
}
else if (IS("-")) /* end of options; use stdin */
} else if (IS("-")) /* end of options; use stdin */
break;
else if (IS("-l")) /* list */
++listing;
else if (IS("-o")) /* output file */
{
else if (IS("-o")) { /* output file */
output = argv[++i];
if (output == NULL || *output == 0 || (*output == '-' && output[1] != 0))
usage("'-o' needs argument");
if (IS("-")) output = NULL;
}
else if (IS("-p")) /* parse only */
} else if (IS("-p")) /* parse only */
dumping = 0;
else if (IS("-s")) /* strip debug information */
stripping = 1;
@ -108,13 +99,11 @@ static int doargs(int argc, char* argv[])
else /* unknown option */
usage(argv[i]);
}
if (i==argc && (listing || !dumping))
{
if (i == argc && (listing || !dumping)) {
dumping = 0;
argv[--i] = Output;
}
if (version)
{
if (version) {
printf("%s\n", LUA_COPYRIGHT);
if (version == argc - 1) exit(EXIT_SUCCESS);
}
@ -123,16 +112,12 @@ static int doargs(int argc, char* argv[])
#define FUNCTION "(function()end)();\n"
static const char* reader(lua_State* L, void* ud, size_t* size)
{
static const char *reader(lua_State *L, void *ud, size_t *size) {
UNUSED(L);
if ((*(int*)ud)--)
{
if ((*(int *)ud)--) {
*size = sizeof(FUNCTION) - 1;
return FUNCTION;
}
else
{
} else {
*size = 0;
return NULL;
}
@ -140,18 +125,15 @@ static const char* reader(lua_State* L, void* ud, size_t* size)
#define toproto(L,i) getproto(s2v(L->top.p+(i)))
static const Proto* combine(lua_State* L, int n)
{
static const Proto *combine(lua_State *L, int n) {
if (n == 1)
return toproto(L, -1);
else
{
else {
Proto *f;
int i = n;
if (lua_load(L, reader, &i, "=(" PROGNAME ")", NULL) != LUA_OK) fatal(lua_tostring(L, -1));
f = toproto(L, -1);
for (i=0; i<n; i++)
{
for (i = 0; i < n; i++) {
f->p[i] = toproto(L, i - n - 1);
if (f->p[i]->sizeupvalues > 0) f->p[i]->upvalues[0].instack = 0;
}
@ -159,29 +141,25 @@ static const Proto* combine(lua_State* L, int n)
}
}
static int writer(lua_State* L, const void* p, size_t size, void* u)
{
static int writer(lua_State *L, const void *p, size_t size, void *u) {
UNUSED(L);
return (fwrite(p, size, 1, (FILE *)u) != 1) && (size != 0);
}
static int pmain(lua_State* L)
{
static int pmain(lua_State *L) {
int argc = (int)lua_tointeger(L, 1);
char **argv = (char **)lua_touserdata(L, 2);
const Proto *f;
int i;
tmname = G(L)->tmname;
if (!lua_checkstack(L, argc)) fatal("too many input files");
for (i=0; i<argc; i++)
{
for (i = 0; i < argc; i++) {
const char *filename = IS("-") ? NULL : argv[i];
if (luaL_loadfile(L, filename) != LUA_OK) fatal(lua_tostring(L, -1));
}
f = combine(L, argc);
if (listing) luaU_print(f, listing > 1);
if (dumping)
{
if (dumping) {
FILE *D = (output == NULL) ? stdout : fopen(output, "wb");
if (D == NULL) cannot("open");
lua_lock(L);
@ -193,11 +171,11 @@ static int pmain(lua_State* L)
return 0;
}
int main(int argc, char* argv[])
{
int main(int argc, char *argv[]) {
lua_State *L;
int i = doargs(argc, argv);
argc-=i; argv+=i;
argc -= i;
argv += i;
if (argc <= 0) usage("no input files given");
L = luaL_newstate();
if (L == NULL) fatal("cannot create state: not enough memory");
@ -217,16 +195,13 @@ int main(int argc, char* argv[])
#define VOID(p) ((const void*)(p))
#define eventname(i) (getstr(tmname[i]))
static void PrintString(const TString* ts)
{
static void PrintString(const TString *ts) {
const char *s = getstr(ts);
size_t i, n = tsslen(ts);
printf("\"");
for (i=0; i<n; i++)
{
for (i = 0; i < n; i++) {
int c = (int)(unsigned char)s[i];
switch (c)
{
switch (c) {
case '"':
printf("\\\"");
break;
@ -255,18 +230,17 @@ static void PrintString(const TString* ts)
printf("\\v");
break;
default:
if (isprint(c)) printf("%c",c); else printf("\\%03d",c);
if (isprint(c)) printf("%c", c);
else printf("\\%03d", c);
break;
}
}
printf("\"");
}
static void PrintType(const Proto* f, int i)
{
static void PrintType(const Proto *f, int i) {
const TValue *o = &f->k[i];
switch (ttypetag(o))
{
switch (ttypetag(o)) {
case LUA_VNIL:
printf("N");
break;
@ -291,11 +265,9 @@ static void PrintType(const Proto* f, int i)
printf("\t");
}
static void PrintConstant(const Proto* f, int i)
{
static void PrintConstant(const Proto *f, int i) {
const TValue *o = &f->k[i];
switch (ttypetag(o))
{
switch (ttypetag(o)) {
case LUA_VNIL:
printf("nil");
break;
@ -305,8 +277,7 @@ static void PrintConstant(const Proto* f, int i)
case LUA_VTRUE:
printf("true");
break;
case LUA_VNUMFLT:
{
case LUA_VNUMFLT: {
char buff[100];
sprintf(buff, LUA_NUMBER_FMT, fltvalue(o));
printf("%s", buff);
@ -331,12 +302,10 @@ static void PrintConstant(const Proto* f, int i)
#define EXTRAARGC (EXTRAARG*(MAXARG_C+1))
#define ISK (isk ? "k" : "")
static void PrintCode(const Proto* f)
{
static void PrintCode(const Proto *f) {
const Instruction *code = f->code;
int pc, n = f->sizecode;
for (pc=0; pc<n; pc++)
{
for (pc = 0; pc < n; pc++) {
Instruction i = code[pc];
OpCode o = GET_OPCODE(i);
int a = GETARG_A(i);
@ -350,10 +319,10 @@ static void PrintCode(const Proto* f)
int isk = GETARG_k(i);
int line = luaG_getfuncline(f, pc);
printf("\t%d\t", pc + 1);
if (line>0) printf("[%d]\t",line); else printf("[-]\t");
if (line > 0) printf("[%d]\t", line);
else printf("[-]\t");
printf("%-9s\t", opnames[o]);
switch (o)
{
switch (o) {
case OP_MOVE:
printf("%d %d", a, b);
break;
@ -365,11 +334,13 @@ static void PrintCode(const Proto* f)
break;
case OP_LOADK:
printf("%d %d", a, bx);
printf(COMMENT); PrintConstant(f,bx);
printf(COMMENT);
PrintConstant(f, bx);
break;
case OP_LOADKX:
printf("%d", a);
printf(COMMENT); PrintConstant(f,EXTRAARG);
printf(COMMENT);
PrintConstant(f, EXTRAARG);
break;
case OP_LOADFALSE:
printf("%d", a);
@ -395,7 +366,8 @@ static void PrintCode(const Proto* f)
case OP_GETTABUP:
printf("%d %d %d", a, b, c);
printf(COMMENT "%s", UPVALNAME(b));
printf(" "); PrintConstant(f,c);
printf(" ");
PrintConstant(f, c);
break;
case OP_GETTABLE:
printf("%d %d %d", a, b, c);
@ -405,12 +377,14 @@ static void PrintCode(const Proto* f)
break;
case OP_GETFIELD:
printf("%d %d %d", a, b, c);
printf(COMMENT); PrintConstant(f,c);
printf(COMMENT);
PrintConstant(f, c);
break;
case OP_SETTABUP:
printf("%d %d %d%s", a, b, c, ISK);
printf(COMMENT "%s", UPVALNAME(a));
printf(" "); PrintConstant(f,b);
printf(" ");
PrintConstant(f, b);
if (isk) { printf(" "); PrintConstant(f, c); }
break;
case OP_SETTABLE:
@ -423,7 +397,8 @@ static void PrintCode(const Proto* f)
break;
case OP_SETFIELD:
printf("%d %d %d%s", a, b, c, ISK);
printf(COMMENT); PrintConstant(f,b);
printf(COMMENT);
PrintConstant(f, b);
if (isk) { printf(" "); PrintConstant(f, c); }
break;
case OP_NEWTABLE:
@ -439,43 +414,53 @@ static void PrintCode(const Proto* f)
break;
case OP_ADDK:
printf("%d %d %d", a, b, c);
printf(COMMENT); PrintConstant(f,c);
printf(COMMENT);
PrintConstant(f, c);
break;
case OP_SUBK:
printf("%d %d %d", a, b, c);
printf(COMMENT); PrintConstant(f,c);
printf(COMMENT);
PrintConstant(f, c);
break;
case OP_MULK:
printf("%d %d %d", a, b, c);
printf(COMMENT); PrintConstant(f,c);
printf(COMMENT);
PrintConstant(f, c);
break;
case OP_MODK:
printf("%d %d %d", a, b, c);
printf(COMMENT); PrintConstant(f,c);
printf(COMMENT);
PrintConstant(f, c);
break;
case OP_POWK:
printf("%d %d %d", a, b, c);
printf(COMMENT); PrintConstant(f,c);
printf(COMMENT);
PrintConstant(f, c);
break;
case OP_DIVK:
printf("%d %d %d", a, b, c);
printf(COMMENT); PrintConstant(f,c);
printf(COMMENT);
PrintConstant(f, c);
break;
case OP_IDIVK:
printf("%d %d %d", a, b, c);
printf(COMMENT); PrintConstant(f,c);
printf(COMMENT);
PrintConstant(f, c);
break;
case OP_BANDK:
printf("%d %d %d", a, b, c);
printf(COMMENT); PrintConstant(f,c);
printf(COMMENT);
PrintConstant(f, c);
break;
case OP_BORK:
printf("%d %d %d", a, b, c);
printf(COMMENT); PrintConstant(f,c);
printf(COMMENT);
PrintConstant(f, c);
break;
case OP_BXORK:
printf("%d %d %d", a, b, c);
printf(COMMENT); PrintConstant(f,c);
printf(COMMENT);
PrintConstant(f, c);
break;
case OP_SHRI:
printf("%d %d %d", a, b, sc);
@ -530,7 +515,8 @@ static void PrintCode(const Proto* f)
break;
case OP_MMBINK:
printf("%d %d %d %d", a, b, c, isk);
printf(COMMENT "%s ",eventname(c)); PrintConstant(f,b);
printf(COMMENT "%s ", eventname(c));
PrintConstant(f, b);
if (isk) printf(" flip");
break;
case OP_UNM:
@ -569,7 +555,8 @@ static void PrintCode(const Proto* f)
break;
case OP_EQK:
printf("%d %d %d", a, b, isk);
printf(COMMENT); PrintConstant(f,b);
printf(COMMENT);
PrintConstant(f, b);
break;
case OP_EQI:
printf("%d %d %d", a, sb, isk);
@ -595,8 +582,10 @@ static void PrintCode(const Proto* f)
case OP_CALL:
printf("%d %d %d", a, b, c);
printf(COMMENT);
if (b==0) printf("all in "); else printf("%d in ",b-1);
if (c==0) printf("all out"); else printf("%d out",c-1);
if (b == 0) printf("all in ");
else printf("%d in ", b - 1);
if (c == 0) printf("all out");
else printf("%d out", c - 1);
break;
case OP_TAILCALL:
printf("%d %d %d%s", a, b, c, ISK);
@ -605,7 +594,8 @@ static void PrintCode(const Proto* f)
case OP_RETURN:
printf("%d %d %d%s", a, b, c, ISK);
printf(COMMENT);
if (b==0) printf("all out"); else printf("%d out",b-1);
if (b == 0) printf("all out");
else printf("%d out", b - 1);
break;
case OP_RETURN0:
break;
@ -642,7 +632,8 @@ static void PrintCode(const Proto* f)
case OP_VARARG:
printf("%d %d", a, c);
printf(COMMENT);
if (c==0) printf("all out"); else printf("%d out",c-1);
if (c == 0) printf("all out");
else printf("%d out", c - 1);
break;
case OP_VARARGPREP:
printf("%d", a);
@ -665,8 +656,7 @@ static void PrintCode(const Proto* f)
#define SS(x) ((x==1)?"":"s")
#define S(x) (int)(x),SS(x)
static void PrintHeader(const Proto* f)
{
static void PrintHeader(const Proto *f) {
const char *s = f->source ? getstr(f->source) : "=?";
if (*s == '@' || *s == '=')
s++;
@ -685,13 +675,11 @@ static void PrintHeader(const Proto* f)
S(f->sizelocvars), S(f->sizek), S(f->sizep));
}
static void PrintDebug(const Proto* f)
{
static void PrintDebug(const Proto *f) {
int i, n;
n = f->sizek;
printf("constants (%d) for %p:\n", n, VOID(f));
for (i=0; i<n; i++)
{
for (i = 0; i < n; i++) {
printf("\t%d\t", i);
PrintType(f, i);
PrintConstant(f, i);
@ -699,22 +687,19 @@ static void PrintDebug(const Proto* f)
}
n = f->sizelocvars;
printf("locals (%d) for %p:\n", n, VOID(f));
for (i=0; i<n; i++)
{
for (i = 0; i < n; i++) {
printf("\t%d\t%s\t%d\t%d\n",
i, getstr(f->locvars[i].varname), f->locvars[i].startpc + 1, f->locvars[i].endpc + 1);
}
n = f->sizeupvalues;
printf("upvalues (%d) for %p:\n", n, VOID(f));
for (i=0; i<n; i++)
{
for (i = 0; i < n; i++) {
printf("\t%d\t%s\t%d\t%d\n",
i, UPVALNAME(i), f->upvalues[i].instack, f->upvalues[i].idx);
}
}
static void PrintFunction(const Proto* f, int full)
{
static void PrintFunction(const Proto *f, int full) {
int i, n = f->sizep;
PrintHeader(f);
PrintCode(f);

View file

@ -117,8 +117,7 @@ static TString *loadStringN (LoadState *S, Proto *p) {
char buff[LUAI_MAXSHORTLEN];
loadVector(S, buff, size); /* load string into buffer */
ts = luaS_newlstr(L, buff, size); /* create string */
}
else { /* long string */
} else { /* long string */
ts = luaS_createlngstrobj(L, size); /* create string */
setsvalue2s(L, L->top.p, ts); /* anchor it ('loadVector' can GC) */
luaD_inctop(L);
@ -182,7 +181,8 @@ static void loadConstants (LoadState *S, Proto *f) {
case LUA_VLNGSTR:
setsvalue2n(S->L, o, loadString(S, f));
break;
default: lua_assert(0);
default:
lua_assert(0);
}
}
}

View file

@ -195,8 +195,7 @@ static int byteoffset (lua_State *L) {
if (n == 0) {
/* find beginning of current byte sequence */
while (posi > 0 && iscontp(s + posi)) posi--;
}
else {
} else {
if (iscontp(s + posi))
return luaL_error(L, "initial position is a continuation byte");
if (n < 0) {
@ -206,8 +205,7 @@ static int byteoffset (lua_State *L) {
} while (posi > 0 && iscontp(s + posi));
n++;
}
}
else {
} else {
n--; /* do not move for 1st character */
while (n > 0 && posi < (lua_Integer)len) {
do { /* find beginning of next character */

View file

@ -107,12 +107,10 @@ int luaV_tonumber_ (const TValue *obj, lua_Number *n) {
if (ttisinteger(obj)) {
*n = cast_num(ivalue(obj));
return 1;
}
else if (l_strton(obj, &v)) { /* string coercible to number? */
} else if (l_strton(obj, &v)) { /* string coercible to number? */
*n = nvalue(&v); /* convert result of 'luaO_str2num' to a float */
return 1;
}
else
} else
return 0; /* conversion failed */
}
@ -142,8 +140,7 @@ int luaV_tointegerns (const TValue *obj, lua_Integer *p, F2Imod mode) {
else if (ttisinteger(obj)) {
*p = ivalue(obj);
return 1;
}
else
} else
return 0;
}
@ -186,8 +183,7 @@ static int forlimit (lua_State *L, lua_Integer init, const TValue *lim,
if (luai_numlt(0, flim)) { /* if it is positive, it is too large */
if (step < 0) return 1; /* initial value must be less than it */
*p = LUA_MAXINTEGER; /* truncate */
}
else { /* it is less than min integer */
} else { /* it is less than min integer */
if (step > 0) return 1; /* initial value must be greater than it */
*p = LUA_MININTEGER; /* truncate */
}
@ -224,8 +220,7 @@ static int forprep (lua_State *L, StkId ra) {
count = l_castS2U(limit) - l_castS2U(init);
if (step != 1) /* avoid division in the too common case */
count /= l_castS2U(step);
}
else { /* step < 0; descending loop */
} else { /* step < 0; descending loop */
count = l_castS2U(init) - l_castS2U(limit);
/* 'step+1' avoids negating 'mininteger' */
count /= l_castS2U(-(step + 1)) + 1u;
@ -234,9 +229,10 @@ static int forprep (lua_State *L, StkId ra) {
needed anymore) */
setivalue(plimit, l_castU2S(count));
}
}
else { /* try making all values floats */
lua_Number init; lua_Number limit; lua_Number step;
} else { /* try making all values floats */
lua_Number init;
lua_Number limit;
lua_Number step;
if (l_unlikely(!tonumber(plimit, &limit)))
luaG_forerror(L, plimit, "limit");
if (l_unlikely(!tonumber(pstep, &step)))
@ -275,8 +271,7 @@ static int floatforloop (StkId ra) {
chgfltvalue(s2v(ra), idx); /* update internal index */
setfltvalue(s2v(ra + 3), idx); /* and control variable */
return 1; /* jump back */
}
else
} else
return 0; /* finish the loop */
}
@ -297,8 +292,7 @@ void luaV_finishget (lua_State *L, const TValue *t, TValue *key, StkId val,
if (l_unlikely(notm(tm)))
luaG_typeerror(L, t, "index"); /* no metamethod */
/* else will try the metamethod */
}
else { /* 't' is a table */
} else { /* 't' is a table */
lua_assert(isempty(slot));
tm = fasttm(L, hvalue(t)->metatable, TM_INDEX); /* table's metamethod */
if (tm == NULL) { /* no metamethod? */
@ -345,8 +339,7 @@ void luaV_finishset (lua_State *L, const TValue *t, TValue *key,
return;
}
/* else will try the metamethod */
}
else { /* not a table; check metamethod */
} else { /* not a table; check metamethod */
tm = luaT_gettmbyobj(L, t, TM_NEWINDEX);
if (l_unlikely(notm(tm)))
luaG_typeerror(L, t, "index");
@ -392,8 +385,12 @@ static int l_strcmp (const TString *ts1, const TString *ts2) {
else if (zl1 == rl1) /* 's1' is finished? */
return -1; /* 's1' is less than 's2' ('s2' is not finished) */
/* both strings longer than 'zl'; go on comparing after the '\0' */
zl1++; zl2++;
s1 += zl1; rl1 -= zl1; s2 += zl2; rl2 -= zl2;
zl1++;
zl2++;
s1 += zl1;
rl1 -= zl1;
s2 += zl2;
rl2 -= zl2;
}
}
}
@ -485,8 +482,7 @@ l_sinline int LTnum (const TValue *l, const TValue *r) {
return li < ivalue(r); /* both are integers */
else /* 'l' is int and 'r' is float */
return LTintfloat(li, fltvalue(r)); /* l < r ? */
}
else {
} else {
lua_Number lf = fltvalue(l); /* 'l' must be float */
if (ttisfloat(r))
return luai_numlt(lf, fltvalue(r)); /* both are float */
@ -507,8 +503,7 @@ l_sinline int LEnum (const TValue *l, const TValue *r) {
return li <= ivalue(r); /* both are integers */
else /* 'l' is int and 'r' is float */
return LEintfloat(li, fltvalue(r)); /* l <= r ? */
}
else {
} else {
lua_Number lf = fltvalue(l); /* 'l' must be float */
if (ttisfloat(r))
return luai_numle(lf, fltvalue(r)); /* both are float */
@ -583,13 +578,22 @@ int luaV_equalobj (lua_State *L, const TValue *t1, const TValue *t2) {
}
/* values have same type and same variant */
switch (ttypetag(t1)) {
case LUA_VNIL: case LUA_VFALSE: case LUA_VTRUE: return 1;
case LUA_VNUMINT: return (ivalue(t1) == ivalue(t2));
case LUA_VNUMFLT: return luai_numeq(fltvalue(t1), fltvalue(t2));
case LUA_VLIGHTUSERDATA: return pvalue(t1) == pvalue(t2);
case LUA_VLCF: return fvalue(t1) == fvalue(t2);
case LUA_VSHRSTR: return eqshrstr(tsvalue(t1), tsvalue(t2));
case LUA_VLNGSTR: return luaS_eqlngstr(tsvalue(t1), tsvalue(t2));
case LUA_VNIL:
case LUA_VFALSE:
case LUA_VTRUE:
return 1;
case LUA_VNUMINT:
return (ivalue(t1) == ivalue(t2));
case LUA_VNUMFLT:
return luai_numeq(fltvalue(t1), fltvalue(t2));
case LUA_VLIGHTUSERDATA:
return pvalue(t1) == pvalue(t2);
case LUA_VLCF:
return fvalue(t1) == fvalue(t2);
case LUA_VSHRSTR:
return eqshrstr(tsvalue(t1), tsvalue(t2));
case LUA_VLNGSTR:
return luaS_eqlngstr(tsvalue(t1), tsvalue(t2));
case LUA_VUSERDATA: {
if (uvalue(t1) == uvalue(t2)) return 1;
else if (L == NULL) return 0;
@ -653,8 +657,7 @@ void luaV_concat (lua_State *L, int total) {
cast_void(tostring(L, s2v(top - 2))); /* result is first operand */
else if (isemptystr(s2v(top - 2))) { /* first operand is empty string? */
setobjs2s(L, top - 2, top - 1); /* result is second op. */
}
else {
} else {
/* at least two non-empty string values; get as many as possible */
size_t tl = tsslen(tsvalue(s2v(top - 1)));
TString *ts;
@ -671,8 +674,7 @@ void luaV_concat (lua_State *L, int total) {
char buff[LUAI_MAXSHORTLEN];
copy2buff(top, n, buff); /* copy strings to buffer */
ts = luaS_newlstr(L, buff, tl);
}
else { /* long string; copy strings directly to final result */
} else { /* long string; copy strings directly to final result */
ts = luaS_createlngstrobj(L, tl);
copy2buff(top, n, getlngstr(ts));
}
@ -727,8 +729,7 @@ lua_Integer luaV_idiv (lua_State *L, lua_Integer m, lua_Integer n) {
if (n == 0)
luaG_runerror(L, "attempt to divide by zero");
return intop(-, 0, m); /* n==-1; avoid overflow with 0x80000...//-1 */
}
else {
} else {
lua_Integer q = m / n; /* perform C division */
if ((m ^ n) < 0 && m % n != 0) /* 'm/n' would be negative non-integer? */
q -= 1; /* correct result for different rounding */
@ -747,8 +748,7 @@ lua_Integer luaV_mod (lua_State *L, lua_Integer m, lua_Integer n) {
if (n == 0)
luaG_runerror(L, "attempt to perform 'n%%0'");
return 0; /* m % -1 == 0; avoid overflow with 0x80000...%-1 */
}
else {
} else {
lua_Integer r = m % n;
if (r != 0 && (r ^ n) < 0) /* 'm/n' would be non-integer negative? */
r += n; /* correct result for different rounding */
@ -778,8 +778,7 @@ lua_Integer luaV_shiftl (lua_Integer x, lua_Integer y) {
if (y < 0) { /* shift right? */
if (y <= -NBITS) return 0;
else return intop( >>, x, -y);
}
else { /* shift left */
} else { /* shift left */
if (y >= NBITS) return 0;
else return intop( <<, x, y);
}
@ -817,19 +816,29 @@ void luaV_finishOp (lua_State *L) {
Instruction inst = *(ci->u.l.savedpc - 1); /* interrupted instruction */
OpCode op = GET_OPCODE(inst);
switch (op) { /* finish its execution */
case OP_MMBIN: case OP_MMBINI: case OP_MMBINK: {
case OP_MMBIN:
case OP_MMBINI:
case OP_MMBINK: {
setobjs2s(L, base + GETARG_A(*(ci->u.l.savedpc - 2)), --L->top.p);
break;
}
case OP_UNM: case OP_BNOT: case OP_LEN:
case OP_GETTABUP: case OP_GETTABLE: case OP_GETI:
case OP_GETFIELD: case OP_SELF: {
case OP_UNM:
case OP_BNOT:
case OP_LEN:
case OP_GETTABUP:
case OP_GETTABLE:
case OP_GETI:
case OP_GETFIELD:
case OP_SELF: {
setobjs2s(L, base + GETARG_A(inst), --L->top.p);
break;
}
case OP_LT: case OP_LE:
case OP_LTI: case OP_LEI:
case OP_GTI: case OP_GEI:
case OP_LT:
case OP_LE:
case OP_LTI:
case OP_LEI:
case OP_GTI:
case OP_GEI:
case OP_EQ: { /* note that 'OP_EQI'/'OP_EQK' cannot yield */
int res = !l_isfalse(s2v(L->top.p - 1));
L->top.p--;
@ -1205,7 +1214,8 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
vmcase(OP_LOADKX) {
StkId ra = RA(i);
TValue *rb;
rb = k + GETARG_Ax(*pc); pc++;
rb = k + GETARG_Ax(*pc);
pc++;
setobj2s(L, ra, rb);
vmbreak;
}
@ -1254,8 +1264,7 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
TString *key = tsvalue(rc); /* key must be a short string */
if (luaV_fastget(L, upval, key, slot, luaH_getshortstr)) {
setobj2s(L, ra, slot);
}
else
} else
Protect(luaV_finishget(L, upval, rc, ra, slot));
vmbreak;
}
@ -1269,8 +1278,7 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
? (cast_void(n = ivalue(rc)), luaV_fastgeti(L, rb, n, slot))
: luaV_fastget(L, rb, rc, slot, luaH_get)) {
setobj2s(L, ra, slot);
}
else
} else
Protect(luaV_finishget(L, rb, rc, ra, slot));
vmbreak;
}
@ -1281,8 +1289,7 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
int c = GETARG_C(i);
if (luaV_fastgeti(L, rb, c, slot)) {
setobj2s(L, ra, slot);
}
else {
} else {
TValue key;
setivalue(&key, c);
Protect(luaV_finishget(L, rb, &key, ra, slot));
@ -1297,8 +1304,7 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
TString *key = tsvalue(rc); /* key must be a short string */
if (luaV_fastget(L, rb, key, slot, luaH_getshortstr)) {
setobj2s(L, ra, slot);
}
else
} else
Protect(luaV_finishget(L, rb, rc, ra, slot));
vmbreak;
}
@ -1310,8 +1316,7 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
TString *key = tsvalue(rb); /* key must be a short string */
if (luaV_fastget(L, upval, key, slot, luaH_getshortstr)) {
luaV_finishfastset(L, upval, slot, rc);
}
else
} else
Protect(luaV_finishset(L, upval, rb, rc, slot));
vmbreak;
}
@ -1325,8 +1330,7 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
? (cast_void(n = ivalue(rb)), luaV_fastgeti(L, s2v(ra), n, slot))
: luaV_fastget(L, s2v(ra), rb, slot, luaH_get)) {
luaV_finishfastset(L, s2v(ra), slot, rc);
}
else
} else
Protect(luaV_finishset(L, s2v(ra), rb, rc, slot));
vmbreak;
}
@ -1337,8 +1341,7 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
TValue *rc = RKC(i);
if (luaV_fastgeti(L, s2v(ra), c, slot)) {
luaV_finishfastset(L, s2v(ra), slot, rc);
}
else {
} else {
TValue key;
setivalue(&key, c);
Protect(luaV_finishset(L, s2v(ra), &key, rc, slot));
@ -1353,8 +1356,7 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
TString *key = tsvalue(rb); /* key must be a short string */
if (luaV_fastget(L, s2v(ra), key, slot, luaH_getshortstr)) {
luaV_finishfastset(L, s2v(ra), slot, rc);
}
else
} else
Protect(luaV_finishset(L, s2v(ra), rb, rc, slot));
vmbreak;
}
@ -1386,8 +1388,7 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
setobj2s(L, ra + 1, rb);
if (luaV_fastget(L, rb, key, slot, luaH_getstr)) {
setobj2s(L, ra, slot);
}
else
} else
Protect(luaV_finishget(L, rb, rc, ra, slot));
vmbreak;
}
@ -1443,7 +1444,8 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
int ic = GETARG_sC(i);
lua_Integer ib;
if (tointegerns(rb, &ib)) {
pc++; setivalue(s2v(ra), luaV_shiftl(ib, -ic));
pc++;
setivalue(s2v(ra), luaV_shiftl(ib, -ic));
}
vmbreak;
}
@ -1453,7 +1455,8 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
int ic = GETARG_sC(i);
lua_Integer ib;
if (tointegerns(rb, &ib)) {
pc++; setivalue(s2v(ra), luaV_shiftl(ic, ib));
pc++;
setivalue(s2v(ra), luaV_shiftl(ic, ib));
}
vmbreak;
}
@ -1544,11 +1547,9 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
if (ttisinteger(rb)) {
lua_Integer ib = ivalue(rb);
setivalue(s2v(ra), intop(-, 0, ib));
}
else if (tonumberns(rb, nb)) {
} else if (tonumberns(rb, nb)) {
setfltvalue(s2v(ra), luai_numunm(L, nb));
}
else
} else
Protect(luaT_trybinTM(L, rb, rb, ra, TM_UNM));
vmbreak;
}
@ -1558,8 +1559,7 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
lua_Integer ib;
if (tointegerns(rb, &ib)) {
setivalue(s2v(ra), intop(^, ~l_castS2U(0), ib));
}
else
} else
Protect(luaT_trybinTM(L, rb, rb, ra, TM_BNOT));
vmbreak;
}
@ -1742,8 +1742,7 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
savepc(ci);
luaD_poscall(L, ci, 0); /* no hurry... */
trap = 1;
}
else { /* do the 'poscall' here */
} else { /* do the 'poscall' here */
int nres;
L->ci = ci->previous; /* back to caller */
L->top.p = base - 1;
@ -1759,8 +1758,7 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
savepc(ci);
luaD_poscall(L, ci, 1); /* no hurry... */
trap = 1;
}
else { /* do the 'poscall' here */
} else { /* do the 'poscall' here */
int nres = ci->nresults;
L->ci = ci->previous; /* back to caller */
if (nres == 0)
@ -1794,8 +1792,7 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
setivalue(s2v(ra + 3), idx); /* and control variable */
pc -= GETARG_Bx(i); /* jump back */
}
}
else if (floatforloop(ra)) /* float loop */
} else if (floatforloop(ra)) /* float loop */
pc -= GETARG_Bx(i); /* jump back */
updatetrap(ci); /* allows a signal to break the loop */
vmbreak;
@ -1832,7 +1829,8 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
i = *(pc++); /* go to next instruction */
lua_assert(GET_OPCODE(i) == OP_TFORLOOP && ra == RA(i));
goto l_tforloop;
}}
}
}
vmcase(OP_TFORLOOP) {
l_tforloop: {
StkId ra = RA(i);
@ -1841,7 +1839,8 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
pc -= GETARG_Bx(i); /* jump back */
}
vmbreak;
}}
}
}
vmcase(OP_SETLIST) {
StkId ra = RA(i);
int n = GETARG_B(i);

View file

@ -363,7 +363,8 @@ static int CmdLFHitagSSim(const char *Cmd) {
void *argtable[] = {
arg_param_begin,
arg_lit0("8", "82xx", "simulate 8268/8310"),
arg_param_end};
arg_param_end
};
CLIExecWithReturn(ctx, Cmd, argtable, true);
// bool use_82xx = arg_get_lit(ctx, 1); // not implemented yet

View file

@ -536,8 +536,7 @@ SWIG_TypePrettyName(const swig_type_info *type) {
for (s = type->str; *s; s++)
if (*s == '|') last_name = s + 1;
return last_name;
}
else
} else
return type->name;
}
@ -963,8 +962,7 @@ static const char *(lua_tolstring)(lua_State *L, int idx, size_t *len) {
prefixed with the location of the innermost Lua call-point
(as formatted by luaL_where). */
SWIGRUNTIME void
SWIG_Lua_pusherrstring (lua_State *L, const char *str)
{
SWIG_Lua_pusherrstring(lua_State *L, const char *str) {
luaL_where(L, 1);
lua_pushstring(L, str);
lua_concat(L, 2);
@ -974,8 +972,7 @@ SWIG_Lua_pusherrstring (lua_State *L, const char *str)
the Lua stack, like lua_pushfstring, but prefixed with the
location of the innermost Lua call-point (as formatted by luaL_where). */
SWIGRUNTIME void
SWIG_Lua_pushferrstring (lua_State *L, const char *fmt, ...)
{
SWIG_Lua_pushferrstring(lua_State *L, const char *fmt, ...) {
va_list argp;
va_start(argp, fmt);
luaL_where(L, 1);
@ -1153,8 +1150,7 @@ SWIG_Lua_SetModule(lua_State *L, swig_module_info *module) {
/* this function is called when trying to set an immutable.
default action is to print an error.
This can removed with a compile flag SWIGLUA_IGNORE_SET_IMMUTABLE */
SWIGINTERN int SWIG_Lua_set_immutable(lua_State *L)
{
SWIGINTERN int SWIG_Lua_set_immutable(lua_State *L) {
/* there should be 1 param passed in: the new value */
#ifndef SWIGLUA_IGNORE_SET_IMMUTABLE
lua_pop(L, 1); /* remove it */
@ -1170,8 +1166,7 @@ SWIGRUNTIME void SWIG_Lua_NewPackedObj(lua_State *L,void *ptr,size_t size,swig_t
static int swig_lua_elua_emulate_unique_key;
/* This function emulates eLua rotables behaviour. It loads a rotable definition into the usual lua table. */
SWIGINTERN void SWIG_Lua_elua_emulate_register(lua_State *L, const swig_elua_entry *table)
{
SWIGINTERN void SWIG_Lua_elua_emulate_register(lua_State *L, const swig_elua_entry *table) {
int i, table_parsed, parsed_tables_array, target_table;
assert(lua_istable(L, -1));
target_table = lua_gettop(L);
@ -1188,8 +1183,7 @@ SWIGINTERN void SWIG_Lua_elua_emulate_register(lua_State *L, const swig_elua_ent
lua_rawsetp(L, parsed_tables_array, table);
table_parsed = 0;
const int SWIGUNUSED pairs_start = lua_gettop(L);
for(i = 0;table[i].key.type != LUA_TNIL || table[i].value.type != LUA_TNIL;i++)
{
for (i = 0; table[i].key.type != LUA_TNIL || table[i].value.type != LUA_TNIL; i++) {
const swig_elua_entry *entry = table + i;
int is_metatable = 0;
switch (entry->key.type) {
@ -1254,16 +1248,14 @@ SWIGINTERN void SWIG_Lua_elua_emulate_register(lua_State *L, const swig_elua_ent
assert(lua_gettop(L) == target_table);
}
SWIGINTERN void SWIG_Lua_elua_emulate_register_clear(lua_State *L)
{
SWIGINTERN void SWIG_Lua_elua_emulate_register_clear(lua_State *L) {
lua_pushnil(L);
lua_rawsetp(L, LUA_REGISTRYINDEX, &swig_lua_elua_emulate_unique_key);
}
SWIGINTERN void SWIG_Lua_get_class_registry(lua_State *L);
SWIGINTERN int SWIG_Lua_emulate_elua_getmetatable(lua_State *L)
{
SWIGINTERN int SWIG_Lua_emulate_elua_getmetatable(lua_State *L) {
SWIG_check_num_args("getmetatable(SWIG eLua emulation)", 1, 1);
SWIG_Lua_get_class_registry(L);
lua_getfield(L, -1, "lua_getmetatable");
@ -1288,8 +1280,7 @@ fail:
return 0;
}
SWIGINTERN void SWIG_Lua_emulate_elua_swap_getmetatable(lua_State *L)
{
SWIGINTERN void SWIG_Lua_emulate_elua_swap_getmetatable(lua_State *L) {
SWIG_Lua_get_class_registry(L);
lua_pushglobaltable(L);
lua_pushstring(L, "lua_getmetatable");
@ -1309,8 +1300,7 @@ SWIGINTERN void SWIG_Lua_emulate_elua_swap_getmetatable(lua_State *L)
* global variable support code: namespaces and modules (which are the same thing)
* ----------------------------------------------------------------------------- */
SWIGINTERN int SWIG_Lua_namespace_get(lua_State *L)
{
SWIGINTERN int SWIG_Lua_namespace_get(lua_State *L) {
/* there should be 2 params passed in
(1) table (not the meta table)
(2) string name of the attribute
@ -1324,8 +1314,8 @@ SWIGINTERN int SWIG_Lua_namespace_get(lua_State *L)
lua_pushvalue(L, 2); /* key */
lua_rawget(L, -2);
lua_remove(L, -2); /* stack tidy, remove .get table */
if (lua_iscfunction(L,-1))
{ /* found it so call the fn & return its value */
if (lua_iscfunction(L, -1)) {
/* found it so call the fn & return its value */
lua_call(L, 0, 1); /* 1 value in (userdata),1 out (result) */
lua_remove(L, -2); /* stack tidy, remove metatable */
return 1;
@ -1337,8 +1327,8 @@ SWIGINTERN int SWIG_Lua_namespace_get(lua_State *L)
lua_pushvalue(L, 2); /* key */
lua_rawget(L, -2); /* look for the fn */
lua_remove(L, -2); /* stack tidy, remove .fn table */
if (lua_isfunction(L,-1)) /* note: whether it's a C function or lua function */
{ /* found it so return the fn & let lua call it */
if (lua_isfunction(L, -1)) { /* note: whether it's a C function or lua function */
/* found it so return the fn & let lua call it */
lua_remove(L, -2); /* stack tidy, remove metatable */
return 1;
}
@ -1346,8 +1336,7 @@ SWIGINTERN int SWIG_Lua_namespace_get(lua_State *L)
return 0;
}
SWIGINTERN int SWIG_Lua_namespace_set(lua_State *L)
{
SWIGINTERN int SWIG_Lua_namespace_set(lua_State *L) {
/* there should be 3 params passed in
(1) table (not the meta table)
(2) string name of the attribute
@ -1359,13 +1348,12 @@ SWIGINTERN int SWIG_Lua_namespace_set(lua_State *L)
assert(lua_istable(L, -1));
SWIG_Lua_get_table(L, ".set"); /* find the .set table */
if (lua_istable(L,-1))
{
if (lua_istable(L, -1)) {
/* look for the key in the .set table */
lua_pushvalue(L, 2); /* key */
lua_rawget(L, -2);
if (lua_iscfunction(L,-1))
{ /* found it so call the fn & return its value */
if (lua_iscfunction(L, -1)) {
/* found it so call the fn & return its value */
lua_pushvalue(L, 3); /* value */
lua_call(L, 1, 0);
return 0;
@ -1384,8 +1372,7 @@ SWIGINTERN void SWIG_Lua_add_variable(lua_State *L,const char *name,lua_CFuncti
SWIGINTERN void SWIG_Lua_class_register(lua_State *L, swig_lua_class *clss);
/* helper function - register namespace methods and attributes into namespace */
SWIGINTERN int SWIG_Lua_add_namespace_details(lua_State *L, swig_lua_namespace *ns)
{
SWIGINTERN int SWIG_Lua_add_namespace_details(lua_State *L, swig_lua_namespace *ns) {
int i;
/* There must be namespace table (not metatable) at the top of the stack */
assert(lua_istable(L, -1));
@ -1408,8 +1395,7 @@ SWIGINTERN int SWIG_Lua_add_namespace_details(lua_State *L, swig_lua_namespace *
}
/* Register all classes in the namespace */
SWIGINTERN void SWIG_Lua_add_namespace_classes(lua_State *L, swig_lua_namespace *ns)
{
SWIGINTERN void SWIG_Lua_add_namespace_classes(lua_State *L, swig_lua_namespace *ns) {
swig_lua_class **classes;
/* There must be a module/namespace table at the top of the stack */
@ -1430,8 +1416,7 @@ SWIGINTERN void SWIG_Lua_add_namespace_classes(lua_State *L, swig_lua_namespace
when function is called).
Function always returns newly registered table on top of the stack.
*/
SWIGINTERN void SWIG_Lua_namespace_register(lua_State *L, swig_lua_namespace *ns, int reg)
{
SWIGINTERN void SWIG_Lua_namespace_register(lua_State *L, swig_lua_namespace *ns, int reg) {
swig_lua_namespace **sub_namespace;
/* 1 argument - table on the top of the stack */
const int SWIGUNUSED begin = lua_gettop(L);
@ -1491,8 +1476,7 @@ SWIGINTERN void SWIG_Lua_get_class_metatable(lua_State *L,const char *cname);
typedef int (*swig_lua_base_iterator_func)(lua_State *, swig_type_info *, int, int *ret);
SWIGINTERN int SWIG_Lua_iterate_bases(lua_State *L, swig_type_info *SWIGUNUSED swig_type,
int first_arg, swig_lua_base_iterator_func func, int *const ret)
{
int first_arg, swig_lua_base_iterator_func func, int *const ret) {
/* first_arg - position of the object in stack. Everything that is above are arguments
* and is passed to every evocation of the func */
int last_arg = lua_gettop(L);/* position of last argument */
@ -1523,8 +1507,7 @@ SWIGINTERN int SWIG_Lua_iterate_bases(lua_State *L, swig_type_info * SWIGUNUSED
if (ret)
*ret = 0;
if(bases_count>0)
{
if (bases_count > 0) {
int to_remove;
size_t i;
int j;
@ -1590,8 +1573,7 @@ SWIGINTERN int SWIG_Lua_iterate_bases(lua_State *L, swig_type_info * SWIGUNUSED
* It returns an error code. Number of function return values is passed inside 'ret'.
* first_arg is not used in this function because function always has 2 arguments.
*/
SWIGINTERN int SWIG_Lua_class_do_get_item(lua_State *L, swig_type_info *type, int SWIGUNUSED first_arg, int *ret)
{
SWIGINTERN int SWIG_Lua_class_do_get_item(lua_State *L, swig_type_info *type, int SWIGUNUSED first_arg, int *ret) {
/* there should be 2 params passed in
(1) userdata (not the meta table)
(2) string name of the attribute
@ -1607,8 +1589,8 @@ SWIGINTERN int SWIG_Lua_class_do_get_item(lua_State *L, swig_type_info *type, i
/* NEW: looks for the __getitem() fn
this is a user provided get fn */
SWIG_Lua_get_table(L, "__getitem"); /* find the __getitem fn */
if (lua_iscfunction(L,-1)) /* if it's there */
{ /* found it so call the fn & return its value */
if (lua_iscfunction(L, -1)) { /* if it's there */
/* found it so call the fn & return its value */
lua_pushvalue(L, substack_start + 1); /* the userdata */
lua_pushvalue(L, substack_start + 2); /* the parameter */
lua_call(L, 2, 1); /* 2 value in (userdata),1 out (result) */
@ -1629,8 +1611,7 @@ SWIGINTERN int SWIG_Lua_class_do_get_item(lua_State *L, swig_type_info *type, i
* It returns an error code. Number of function return values is passed inside 'ret'.
* first_arg is not used in this function because function always has 2 arguments.
*/
SWIGINTERN int SWIG_Lua_class_do_get(lua_State *L, swig_type_info *type, int SWIGUNUSED first_arg, int *ret)
{
SWIGINTERN int SWIG_Lua_class_do_get(lua_State *L, swig_type_info *type, int SWIGUNUSED first_arg, int *ret) {
/* there should be 2 params passed in
(1) userdata (not the meta table)
(2) string name of the attribute
@ -1649,8 +1630,8 @@ SWIGINTERN int SWIG_Lua_class_do_get(lua_State *L, swig_type_info *type, int SW
lua_pushvalue(L, substack_start + 2); /* key */
lua_rawget(L, -2);
lua_remove(L, -2); /* stack tidy, remove .get table */
if (lua_iscfunction(L,-1))
{ /* found it so call the fn & return its value */
if (lua_iscfunction(L, -1)) {
/* found it so call the fn & return its value */
lua_pushvalue(L, substack_start + 1); /* the userdata */
lua_call(L, 1, 1); /* 1 value in (userdata),1 out (result) */
lua_remove(L, -2); /* stack tidy, remove metatable */
@ -1665,8 +1646,8 @@ SWIGINTERN int SWIG_Lua_class_do_get(lua_State *L, swig_type_info *type, int SW
lua_pushvalue(L, substack_start + 2); /* key */
lua_rawget(L, -2); /* look for the fn */
lua_remove(L, -2); /* stack tidy, remove .fn table */
if (lua_isfunction(L,-1)) /* note: if it's a C function or lua function */
{ /* found it so return the fn & let lua call it */
if (lua_isfunction(L, -1)) { /* note: if it's a C function or lua function */
/* found it so return the fn & let lua call it */
lua_remove(L, -2); /* stack tidy, remove metatable */
if (ret)
*ret = 1;
@ -1682,8 +1663,7 @@ SWIGINTERN int SWIG_Lua_class_do_get(lua_State *L, swig_type_info *type, int SW
/* the class.get method, performs the lookup of class attributes
*/
SWIGINTERN int SWIG_Lua_class_get(lua_State *L)
{
SWIGINTERN int SWIG_Lua_class_get(lua_State *L) {
/* there should be 2 params passed in
(1) userdata (not the meta table)
(2) string name of the attribute
@ -1709,8 +1689,7 @@ SWIGINTERN int SWIG_Lua_class_get(lua_State *L)
/* helper for the class.set method, performs the lookup of class attributes
* It returns error code. Number of function return values is passed inside 'ret'
*/
SWIGINTERN int SWIG_Lua_class_do_set(lua_State *L, swig_type_info *type, int first_arg, int *ret)
{
SWIGINTERN int SWIG_Lua_class_do_set(lua_State *L, swig_type_info *type, int first_arg, int *ret) {
/* there should be 3 params passed in
(1) table (not the meta table)
(2) string name of the attribute
@ -1727,14 +1706,13 @@ SWIGINTERN int SWIG_Lua_class_do_set(lua_State *L, swig_type_info *type, int fi
*ret = 0; /* it is setter - number of return values is always 0 */
SWIG_Lua_get_table(L, ".set"); /* find the .set table */
if (lua_istable(L,-1))
{
if (lua_istable(L, -1)) {
/* look for the key in the .set table */
lua_pushvalue(L, substack_start + 2); /* key */
lua_rawget(L, -2);
lua_remove(L, -2); /* tidy stack, remove .set table */
if (lua_iscfunction(L,-1))
{ /* found it so call the fn & return its value */
if (lua_iscfunction(L, -1)) {
/* found it so call the fn & return its value */
lua_pushvalue(L, substack_start + 1); /* userdata */
lua_pushvalue(L, substack_start + 3); /* value */
lua_call(L, 2, 0);
@ -1748,8 +1726,8 @@ SWIGINTERN int SWIG_Lua_class_do_set(lua_State *L, swig_type_info *type, int fi
/* NEW: looks for the __setitem() fn
this is a user provided set fn */
SWIG_Lua_get_table(L, "__setitem"); /* find the fn */
if (lua_iscfunction(L,-1)) /* if it's there */
{ /* found it so call the fn & return its value */
if (lua_iscfunction(L, -1)) { /* if it's there */
/* found it so call the fn & return its value */
lua_pushvalue(L, substack_start + 1); /* the userdata */
lua_pushvalue(L, substack_start + 2); /* the parameter */
lua_pushvalue(L, substack_start + 3); /* the value */
@ -1771,8 +1749,7 @@ SWIGINTERN int SWIG_Lua_class_do_set(lua_State *L, swig_type_info *type, int fi
/* This is the actual method exported to Lua. It calls SWIG_Lua_class_do_set and correctly
* handles return values.
*/
SWIGINTERN int SWIG_Lua_class_set(lua_State *L)
{
SWIGINTERN int SWIG_Lua_class_set(lua_State *L) {
/* There should be 3 params passed in
(1) table (not the meta table)
(2) string name of the attribute
@ -1796,8 +1773,7 @@ SWIGINTERN int SWIG_Lua_class_set(lua_State *L)
}
/* the class.destruct method called by the interpreter */
SWIGINTERN int SWIG_Lua_class_destruct(lua_State *L)
{
SWIGINTERN int SWIG_Lua_class_destruct(lua_State *L) {
/* there should be 1 params passed in
(1) userdata (not the meta table) */
swig_lua_userdata *usr;
@ -1805,11 +1781,9 @@ SWIGINTERN int SWIG_Lua_class_destruct(lua_State *L)
assert(lua_isuserdata(L, -1)); /* just in case */
usr = (swig_lua_userdata *)lua_touserdata(L, -1); /* get it */
/* if must be destroyed & has a destructor */
if (usr->own) /* if must be destroyed */
{
if (usr->own) { /* if must be destroyed */
clss = (swig_lua_class *)usr->type->clientdata; /* get the class */
if (clss && clss->destructor) /* there is a destroy fn */
{
if (clss && clss->destructor) { /* there is a destroy fn */
clss->destructor(usr->ptr); /* bye bye */
}
}
@ -1817,8 +1791,7 @@ SWIGINTERN int SWIG_Lua_class_destruct(lua_State *L)
}
/* the class.__tostring method called by the interpreter and print */
SWIGINTERN int SWIG_Lua_class_tostring(lua_State *L)
{
SWIGINTERN int SWIG_Lua_class_tostring(lua_State *L) {
/* there should be 1 param passed in
(1) userdata (not the metatable) */
swig_lua_userdata *userData;
@ -1830,8 +1803,7 @@ SWIGINTERN int SWIG_Lua_class_tostring(lua_State *L)
}
/* to manually disown some userdata */
SWIGINTERN int SWIG_Lua_class_disown(lua_State *L)
{
SWIGINTERN int SWIG_Lua_class_disown(lua_State *L) {
/* there should be 1 params passed in
(1) userdata (not the meta table) */
swig_lua_userdata *usr;
@ -1845,8 +1817,7 @@ SWIGINTERN int SWIG_Lua_class_disown(lua_State *L)
/* lua callable function to compare userdata's value
the issue is that two userdata may point to the same thing
but to lua, they are different objects */
SWIGRUNTIME int SWIG_Lua_class_equal(lua_State *L)
{
SWIGRUNTIME int SWIG_Lua_class_equal(lua_State *L) {
int result;
swig_lua_userdata *usr1, *usr2;
if (!lua_isuserdata(L, 1) || !lua_isuserdata(L, 2)) /* just in case */
@ -1860,8 +1831,7 @@ SWIGRUNTIME int SWIG_Lua_class_equal(lua_State *L)
}
/* populate table at the top of the stack with metamethods that ought to be inherited */
SWIGINTERN void SWIG_Lua_populate_inheritable_metamethods(lua_State *L)
{
SWIGINTERN void SWIG_Lua_populate_inheritable_metamethods(lua_State *L) {
SWIG_Lua_add_boolean(L, "__add", 1);
SWIG_Lua_add_boolean(L, "__sub", 1);
SWIG_Lua_add_boolean(L, "__mul", 1);
@ -1880,8 +1850,7 @@ SWIGINTERN void SWIG_Lua_populate_inheritable_metamethods(lua_State *L)
}
/* creates the swig registry */
SWIGINTERN void SWIG_Lua_create_class_registry(lua_State *L)
{
SWIGINTERN void SWIG_Lua_create_class_registry(lua_State *L) {
/* create main SWIG registry table */
lua_pushstring(L, "SWIG");
lua_newtable(L);
@ -1904,13 +1873,12 @@ SWIGINTERN void SWIG_Lua_create_class_registry(lua_State *L)
}
/* gets the swig registry (or creates it) */
SWIGINTERN void SWIG_Lua_get_class_registry(lua_State *L)
{
SWIGINTERN void SWIG_Lua_get_class_registry(lua_State *L) {
/* add this all into the swig registry: */
lua_pushstring(L, "SWIG");
lua_rawget(L, LUA_REGISTRYINDEX); /* get the registry */
if (!lua_istable(L,-1)) /* not there */
{ /* must be first time, so add it */
if (!lua_istable(L, -1)) { /* not there */
/* must be first time, so add it */
lua_pop(L, 1); /* remove the result */
SWIG_Lua_create_class_registry(L);
/* then get it */
@ -1919,8 +1887,7 @@ SWIGINTERN void SWIG_Lua_get_class_registry(lua_State *L)
}
}
SWIGINTERN void SWIG_Lua_get_inheritable_metamethods(lua_State *L)
{
SWIGINTERN void SWIG_Lua_get_inheritable_metamethods(lua_State *L) {
SWIG_Lua_get_class_registry(L);
lua_pushstring(L, ".library");
lua_rawget(L, -2);
@ -1934,8 +1901,7 @@ SWIGINTERN void SWIG_Lua_get_inheritable_metamethods(lua_State *L)
}
/* Helper function to get the classes metatable from the register */
SWIGINTERN void SWIG_Lua_get_class_metatable(lua_State *L,const char *cname)
{
SWIGINTERN void SWIG_Lua_get_class_metatable(lua_State *L, const char *cname) {
SWIG_Lua_get_class_registry(L); /* get the registry */
lua_pushstring(L, cname); /* get the name */
lua_rawget(L, -2); /* get it */
@ -1949,14 +1915,11 @@ It cannot be done at compile time, as this will not work with hireachies
spread over more than one swig file.
Therefore it must be done at runtime, querying the SWIG type system.
*/
SWIGINTERN void SWIG_Lua_init_base_class(lua_State *L,swig_lua_class *clss)
{
SWIGINTERN void SWIG_Lua_init_base_class(lua_State *L, swig_lua_class *clss) {
int i = 0;
swig_module_info *module = SWIG_GetModule(L);
for(i=0;clss->base_names[i];i++)
{
if (clss->bases[i]==0) /* not found yet */
{
for (i = 0; clss->base_names[i]; i++) {
if (clss->bases[i] == 0) { /* not found yet */
/* lookup and cache the base class */
swig_type_info *info = SWIG_TypeQueryModule(module, module, clss->base_names[i]);
if (info) clss->bases[i] = (swig_lua_class *) info->clientdata;
@ -1966,8 +1929,7 @@ SWIGINTERN void SWIG_Lua_init_base_class(lua_State *L,swig_lua_class *clss)
#if defined(SWIG_LUA_SQUASH_BASES) && (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_LUA)
/* Merges two tables */
SWIGINTERN void SWIG_Lua_merge_tables_by_index(lua_State *L, int target, int source)
{
SWIGINTERN void SWIG_Lua_merge_tables_by_index(lua_State *L, int target, int source) {
/* iterating */
lua_pushnil(L);
while (lua_next(L, source) != 0) {
@ -1982,8 +1944,7 @@ SWIGINTERN void SWIG_Lua_merge_tables_by_index(lua_State *L, int target, int sou
}
/* Merges two tables with given name. original - index of target metatable, base - index of source metatable */
SWIGINTERN void SWIG_Lua_merge_tables(lua_State *L, const char* name, int original, int base)
{
SWIGINTERN void SWIG_Lua_merge_tables(lua_State *L, const char *name, int original, int base) {
/* push original[name], then base[name] */
lua_pushstring(L, name);
lua_rawget(L, original);
@ -1997,8 +1958,7 @@ SWIGINTERN void SWIG_Lua_merge_tables(lua_State *L, const char* name, int origin
}
/* Function takes all symbols from base and adds it to derived class. It's just a helper. */
SWIGINTERN void SWIG_Lua_class_squash_base(lua_State *L, swig_lua_class *base_cls)
{
SWIGINTERN void SWIG_Lua_class_squash_base(lua_State *L, swig_lua_class *base_cls) {
/* There is one parameter - original, i.e. 'derived' class metatable */
assert(lua_istable(L, -1));
int original = lua_gettop(L);
@ -2011,12 +1971,10 @@ SWIGINTERN void SWIG_Lua_class_squash_base(lua_State *L, swig_lua_class *base_cl
}
/* Function squashes all symbols from 'clss' bases into itself */
SWIGINTERN void SWIG_Lua_class_squash_bases(lua_State *L, swig_lua_class *clss)
{
SWIGINTERN void SWIG_Lua_class_squash_bases(lua_State *L, swig_lua_class *clss) {
int i;
SWIG_Lua_get_class_metatable(L, clss->fqname);
for(i=0;clss->base_names[i];i++)
{
for (i = 0; clss->base_names[i]; i++) {
if (clss->bases[i] == 0) /* Somehow it's not found. Skip it */
continue;
/* Thing is: all bases are already registered. Thus they have already executed
@ -2031,15 +1989,13 @@ SWIGINTERN void SWIG_Lua_class_squash_bases(lua_State *L, swig_lua_class *clss)
#if (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_LUA) /* In elua this is useless */
/* helper add a variable to a registered class */
SWIGINTERN void SWIG_Lua_add_variable(lua_State *L,const char *name,lua_CFunction getFn,lua_CFunction setFn)
{
SWIGINTERN void SWIG_Lua_add_variable(lua_State *L, const char *name, lua_CFunction getFn, lua_CFunction setFn) {
assert(lua_istable(L, -1)); /* just in case */
SWIG_Lua_get_table(L, ".get"); /* find the .get table */
assert(lua_istable(L, -1)); /* just in case */
SWIG_Lua_add_function(L, name, getFn);
lua_pop(L, 1); /* tidy stack (remove table) */
if (setFn)
{
if (setFn) {
SWIG_Lua_get_table(L, ".set"); /* find the .set table */
assert(lua_istable(L, -1)); /* just in case */
SWIG_Lua_add_function(L, name, setFn);
@ -2048,14 +2004,12 @@ SWIGINTERN void SWIG_Lua_add_variable(lua_State *L,const char *name,lua_CFuncti
}
/* helper to recursively add class static details (static attributes, operations and constants) */
SWIGINTERN void SWIG_Lua_add_class_static_details(lua_State *L, swig_lua_class *clss)
{
SWIGINTERN void SWIG_Lua_add_class_static_details(lua_State *L, swig_lua_class *clss) {
int i = 0;
/* The class namespace table must be on the top of the stack */
assert(lua_istable(L, -1));
/* call all the base classes first: we can then override these later: */
for(i=0;clss->bases[i];i++)
{
for (i = 0; clss->bases[i]; i++) {
SWIG_Lua_add_class_static_details(L, clss->bases[i]);
}
@ -2065,15 +2019,13 @@ SWIGINTERN void SWIG_Lua_add_class_static_details(lua_State *L, swig_lua_class *
SWIGINTERN void SWIG_Lua_add_class_user_metamethods(lua_State *L, swig_lua_class *clss); /* forward declaration */
/* helper to recursively add class details (attributes & operations) */
SWIGINTERN void SWIG_Lua_add_class_instance_details(lua_State *L, swig_lua_class *clss)
{
SWIGINTERN void SWIG_Lua_add_class_instance_details(lua_State *L, swig_lua_class *clss) {
int i;
size_t bases_count = 0;
/* Add bases to .bases table */
SWIG_Lua_get_table(L, ".bases");
assert(lua_istable(L, -1)); /* just in case */
for(i=0;clss->bases[i];i++)
{
for (i = 0; clss->bases[i]; i++) {
SWIG_Lua_get_class_metatable(L, clss->bases[i]->fqname);
/* Base class must be already registered */
assert(lua_istable(L, -1));
@ -2137,8 +2089,7 @@ SWIGRUNTIME int SWIG_Lua_resolve_metamethod(lua_State *L); /*forward declaration
* SWIG_Lua_resolve_metamethod
* */
SWIGINTERN int SWIG_Lua_do_resolve_metamethod(lua_State *L, const swig_lua_class *clss, int metamethod_name_idx,
int skip_check)
{
int skip_check) {
/* This function is called recursively */
int result = 0;
int i = 0;
@ -2159,8 +2110,7 @@ SWIGINTERN int SWIG_Lua_do_resolve_metamethod(lua_State *L, const swig_lua_class
}
/* Forwarding calls to bases */
for(i=0;clss->bases[i];i++)
{
for (i = 0; clss->bases[i]; i++) {
result = SWIG_Lua_do_resolve_metamethod(L, clss->bases[i], metamethod_name_idx, 0);
if (result)
break;
@ -2171,8 +2121,7 @@ SWIGINTERN int SWIG_Lua_do_resolve_metamethod(lua_State *L, const swig_lua_class
/* The proxy function for metamethod. All parameters are passed as cclosure. Searches for actual method
* and calls it */
SWIGRUNTIME int SWIG_Lua_resolve_metamethod(lua_State *L)
{
SWIGRUNTIME int SWIG_Lua_resolve_metamethod(lua_State *L) {
int numargs;
int metamethod_name_idx;
const swig_lua_class *clss;
@ -2208,8 +2157,7 @@ SWIGRUNTIME int SWIG_Lua_resolve_metamethod(lua_State *L)
* Returns 1 if successfully added, 0 if not added because no base class has it, -1
* if method is defined in the class metatable itself
*/
SWIGINTERN int SWIG_Lua_add_class_user_metamethod(lua_State *L, swig_lua_class *clss, const int metatable_index)
{
SWIGINTERN int SWIG_Lua_add_class_user_metamethod(lua_State *L, swig_lua_class *clss, const int metatable_index) {
int key_index;
int success = 0;
int i = 0;
@ -2229,8 +2177,7 @@ SWIGINTERN int SWIG_Lua_add_class_user_metamethod(lua_State *L, swig_lua_class *
lua_pop(L, 1);
/* Iterating over immediate bases */
for(i=0;clss->bases[i];i++)
{
for (i = 0; clss->bases[i]; i++) {
const swig_lua_class *base = clss->bases[i];
SWIG_Lua_get_class_metatable(L, base->fqname);
lua_pushvalue(L, key_index);
@ -2256,8 +2203,7 @@ SWIGINTERN int SWIG_Lua_add_class_user_metamethod(lua_State *L, swig_lua_class *
return success;
}
SWIGINTERN void SWIG_Lua_add_class_user_metamethods(lua_State *L, swig_lua_class *clss)
{
SWIGINTERN void SWIG_Lua_add_class_user_metamethods(lua_State *L, swig_lua_class *clss) {
int metatable_index;
int metamethods_info_index;
int tostring_undefined;
@ -2313,8 +2259,7 @@ SWIGINTERN void SWIG_Lua_add_class_user_metamethods(lua_State *L, swig_lua_class
}
/* Register class static methods,attributes etc as well as constructor proxy */
SWIGINTERN void SWIG_Lua_class_register_static(lua_State *L, swig_lua_class *clss)
{
SWIGINTERN void SWIG_Lua_class_register_static(lua_State *L, swig_lua_class *clss) {
const int SWIGUNUSED begin = lua_gettop(L);
lua_checkstack(L, 5); /* just in case */
assert(lua_istable(L, -1)); /* just in case */
@ -2328,8 +2273,7 @@ SWIGINTERN void SWIG_Lua_class_register_static(lua_State *L, swig_lua_class *cls
so you can do MyClass(...) as well as new_MyClass(...)
BUT only if a constructor is defined
(this overcomes the problem of pure virtual classes without constructors)*/
if (clss->constructor)
{
if (clss->constructor) {
lua_getmetatable(L, -1);
assert(lua_istable(L, -1)); /* just in case */
SWIG_Lua_add_function(L, "__call", clss->constructor);
@ -2347,8 +2291,7 @@ SWIGINTERN void SWIG_Lua_class_register_static(lua_State *L, swig_lua_class *cls
/* Performs the instance (non-static) class registration process. Metatable for class is created
* and added to the class registry.
*/
SWIGINTERN void SWIG_Lua_class_register_instance(lua_State *L,swig_lua_class *clss)
{
SWIGINTERN void SWIG_Lua_class_register_instance(lua_State *L, swig_lua_class *clss) {
const int SWIGUNUSED begin = lua_gettop(L);
int i;
/* if name already there (class is already registered) then do nothing */
@ -2362,8 +2305,7 @@ SWIGINTERN void SWIG_Lua_class_register_instance(lua_State *L,swig_lua_class *c
}
lua_pop(L, 2); /* tidy stack */
/* Recursively initialize all bases */
for(i=0;clss->bases[i];i++)
{
for (i = 0; clss->bases[i]; i++) {
SWIG_Lua_class_register_instance(L, clss->bases[i]);
}
/* Again, get registry and push name */
@ -2377,8 +2319,7 @@ SWIGINTERN void SWIG_Lua_class_register_instance(lua_State *L,swig_lua_class *c
*/
{
int new_metatable_index = lua_absindex(L, -1);
for(i=0;clss->bases[i];i++)
{
for (i = 0; clss->bases[i]; i++) {
int base_metatable;
SWIG_Lua_get_class_metatable(L, clss->bases[i]->fqname);
base_metatable = lua_absindex(L, -1);
@ -2429,8 +2370,7 @@ SWIGINTERN void SWIG_Lua_class_register_instance(lua_State *L,swig_lua_class *c
assert(lua_gettop(L) == begin);
}
SWIGINTERN void SWIG_Lua_class_register(lua_State *L,swig_lua_class *clss)
{
SWIGINTERN void SWIG_Lua_class_register(lua_State *L, swig_lua_class *clss) {
int SWIGUNUSED begin;
assert(lua_istable(L, -1)); /* This is a table (module or namespace) where classes will be added */
SWIG_Lua_class_register_instance(L, clss);
@ -2467,8 +2407,7 @@ SWIGINTERN void SWIG_Lua_class_register(lua_State *L,swig_lua_class *clss)
#endif /* SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_LUA */
#if (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUA) || (SWIG_LUA_TARGET == SWIG_LUA_FLAVOR_ELUAC)
SWIGINTERN void SWIG_Lua_elua_class_register_instance(lua_State *L, swig_lua_class *clss)
{
SWIGINTERN void SWIG_Lua_elua_class_register_instance(lua_State *L, swig_lua_class *clss) {
const int SWIGUNUSED begin = lua_gettop(L);
int i;
/* if name already there (class is already registered) then do nothing */
@ -2482,8 +2421,7 @@ SWIGINTERN void SWIG_Lua_elua_class_register_instance(lua_State *L, swig_lua_cla
}
lua_pop(L, 2); /* tidy stack */
/* Recursively initialize all bases */
for(i=0;clss->bases[i];i++)
{
for (i = 0; clss->bases[i]; i++) {
SWIG_Lua_elua_class_register_instance(L, clss->bases[i]);
}
/* Again, get registry and push name */
@ -2502,25 +2440,19 @@ SWIGINTERN void SWIG_Lua_elua_class_register_instance(lua_State *L, swig_lua_cla
* ----------------------------------------------------------------------------- */
/* helper to add metatable to new lua object */
SWIGINTERN void SWIG_Lua_AddMetatable(lua_State *L,swig_type_info *type)
{
if (type->clientdata) /* there is clientdata: so add the metatable */
{
SWIGINTERN void SWIG_Lua_AddMetatable(lua_State *L, swig_type_info *type) {
if (type->clientdata) { /* there is clientdata: so add the metatable */
SWIG_Lua_get_class_metatable(L, ((swig_lua_class *)(type->clientdata))->fqname);
if (lua_istable(L,-1))
{
if (lua_istable(L, -1)) {
lua_setmetatable(L, -2);
}
else
{
} else {
lua_pop(L, 1);
}
}
}
/* pushes a new object into the lua stack */
SWIGRUNTIME void SWIG_Lua_NewPointerObj(lua_State *L,void *ptr,swig_type_info *type, int own)
{
SWIGRUNTIME void SWIG_Lua_NewPointerObj(lua_State *L, void *ptr, swig_type_info *type, int own) {
swig_lua_userdata *usr;
if (!ptr) {
lua_pushnil(L);
@ -2537,51 +2469,40 @@ SWIGRUNTIME void SWIG_Lua_NewPointerObj(lua_State *L,void *ptr,swig_type_info *t
/* takes a object from the lua stack & converts it into an object of the correct type
(if possible) */
SWIGRUNTIME int SWIG_Lua_ConvertPtr(lua_State *L,int index,void **ptr,swig_type_info *type,int flags)
{
SWIGRUNTIME int SWIG_Lua_ConvertPtr(lua_State *L, int index, void **ptr, swig_type_info *type, int flags) {
int ret = SWIG_ERROR;
swig_lua_userdata *usr;
swig_cast_info *cast;
/* special case: lua nil => NULL pointer */
if (lua_isnil(L,index))
{
if (lua_isnil(L, index)) {
*ptr = 0;
return (flags & SWIG_POINTER_NO_NULL) ? SWIG_NullReferenceError : SWIG_OK;
}
if (lua_islightuserdata(L,index))
{
if (lua_islightuserdata(L, index)) {
*ptr = lua_touserdata(L, index);
return (flags & SWIG_POINTER_NO_NULL) ? SWIG_NullReferenceError : SWIG_OK;
}
usr = (swig_lua_userdata *)lua_touserdata(L, index); /* get data */
if (usr)
{
if (((flags & SWIG_POINTER_RELEASE) == SWIG_POINTER_RELEASE) && !usr->own)
{
if (usr) {
if (((flags & SWIG_POINTER_RELEASE) == SWIG_POINTER_RELEASE) && !usr->own) {
return SWIG_ERROR_RELEASE_NOT_OWNED;
}
if (flags & SWIG_POINTER_DISOWN) /* must disown the object */
{
if (flags & SWIG_POINTER_DISOWN) { /* must disown the object */
usr->own = 0;
}
if (!type) /* special cast void*, no casting fn */
{
if (!type) { /* special cast void*, no casting fn */
*ptr = usr->ptr;
ret = SWIG_OK;
}
else
{
} else {
cast = SWIG_TypeCheck(usr->type->name, type); /* performs normal type checking */
if (cast)
{
if (cast) {
int newmemory = 0;
*ptr = SWIG_TypeCast(cast, usr->ptr, &newmemory);
assert(!newmemory); /* newmemory handling not yet implemented */
ret = SWIG_OK;
}
}
if ((ret == SWIG_OK) && (flags & SWIG_POINTER_CLEAR))
{
if ((ret == SWIG_OK) && (flags & SWIG_POINTER_CLEAR)) {
usr->ptr = 0;
}
}
@ -2599,8 +2520,7 @@ SWIGRUNTIME void* SWIG_Lua_MustGetPtr(lua_State *L,int index,swig_type_info *typ
}
/* pushes a packed userdata. user for member fn pointers only */
SWIGRUNTIME void SWIG_Lua_NewPackedObj(lua_State *L,void *ptr,size_t size,swig_type_info *type)
{
SWIGRUNTIME void SWIG_Lua_NewPackedObj(lua_State *L, void *ptr, size_t size, swig_type_info *type) {
swig_lua_rawdata *raw;
assert(ptr); /* not acceptable to pass in a NULL value */
raw = (swig_lua_rawdata *)lua_newuserdata(L, sizeof(swig_lua_rawdata) - 1 + size); /* alloc data */
@ -2611,13 +2531,11 @@ SWIGRUNTIME void SWIG_Lua_NewPackedObj(lua_State *L,void *ptr,size_t size,swig_t
}
/* converts a packed userdata. user for member fn pointers only */
SWIGRUNTIME int SWIG_Lua_ConvertPacked(lua_State *L,int index,void *ptr,size_t size,swig_type_info *type)
{
SWIGRUNTIME int SWIG_Lua_ConvertPacked(lua_State *L, int index, void *ptr, size_t size, swig_type_info *type) {
swig_lua_rawdata *raw;
raw = (swig_lua_rawdata *)lua_touserdata(L, index); /* get data */
if (!raw) return SWIG_ERROR; /* error */
if (type==0 || type==raw->type) /* void* or identical type */
{
if (type == 0 || type == raw->type) { /* void* or identical type */
memcpy(ptr, raw->data, size); /* copy it */
return SWIG_OK; /* ok */
}
@ -2625,11 +2543,9 @@ SWIGRUNTIME int SWIG_Lua_ConvertPacked(lua_State *L,int index,void *ptr,size_t
}
/* a function to get the typestring of a piece of data */
SWIGRUNTIME const char *SWIG_Lua_typename(lua_State *L, int tp)
{
SWIGRUNTIME const char *SWIG_Lua_typename(lua_State *L, int tp) {
swig_lua_userdata *usr;
if (lua_isuserdata(L,tp))
{
if (lua_isuserdata(L, tp)) {
usr = (swig_lua_userdata *)lua_touserdata(L, tp); /* get data */
if (usr && usr->type && usr->type->str)
return usr->type->str;
@ -2639,8 +2555,7 @@ SWIGRUNTIME const char *SWIG_Lua_typename(lua_State *L, int tp)
}
/* lua callable function to get the userdata's type */
SWIGRUNTIME int SWIG_Lua_type(lua_State *L)
{
SWIGRUNTIME int SWIG_Lua_type(lua_State *L) {
lua_pushstring(L, SWIG_Lua_typename(L, 1));
return 1;
}
@ -2789,10 +2704,12 @@ static int _wrap_new_pm3__SWIG_0(lua_State* L) {
SWIG_check_num_args("pm3::pm3", 0, 0)
result = (pm3 *)new_pm3__SWIG_0();
SWIG_NewPointerObj(L,result,SWIGTYPE_p_pm3,1); SWIG_arg++;
SWIG_NewPointerObj(L, result, SWIGTYPE_p_pm3, 1);
SWIG_arg++;
return SWIG_arg;
fail: SWIGUNUSED;
fail:
SWIGUNUSED;
lua_error(L);
return 0;
}
@ -2807,10 +2724,12 @@ static int _wrap_new_pm3__SWIG_1(lua_State* L) {
if (!SWIG_lua_isnilstring(L, 1)) SWIG_fail_arg("pm3::pm3", 1, "char *");
arg1 = (char *)lua_tostring(L, 1);
result = (pm3 *)new_pm3__SWIG_1(arg1);
SWIG_NewPointerObj(L,result,SWIGTYPE_p_pm3,1); SWIG_arg++;
SWIG_NewPointerObj(L, result, SWIGTYPE_p_pm3, 1);
SWIG_arg++;
return SWIG_arg;
fail: SWIGUNUSED;
fail:
SWIGUNUSED;
lua_error(L);
return 0;
}
@ -2840,7 +2759,8 @@ static int _wrap_new_pm3(lua_State* L) {
" Possible C/C++ prototypes are:\n"
" pm3::pm3()\n"
" pm3::pm3(char *)\n");
lua_error(L);return 0;
lua_error(L);
return 0;
}
@ -2865,10 +2785,12 @@ static int _wrap_pm3_console(lua_State* L) {
arg3 = (lua_toboolean(L, 3) != 0);
}
result = (int)pm3_console(arg1, arg2, arg3);
lua_pushnumber(L, (lua_Number) result); SWIG_arg++;
lua_pushnumber(L, (lua_Number) result);
SWIG_arg++;
return SWIG_arg;
fail: SWIGUNUSED;
fail:
SWIGUNUSED;
lua_error(L);
return 0;
}
@ -2887,10 +2809,12 @@ static int _wrap_pm3_name_get(lua_State* L) {
}
result = (char *)pm3_name_get(arg1);
lua_pushstring(L,(const char *)result); SWIG_arg++;
lua_pushstring(L, (const char *)result);
SWIG_arg++;
return SWIG_arg;
fail: SWIGUNUSED;
fail:
SWIGUNUSED;
lua_error(L);
return 0;
}
@ -2909,10 +2833,12 @@ static int _wrap_pm3_grabbed_output_get(lua_State* L) {
}
result = (char *)pm3_grabbed_output_get(arg1);
lua_pushstring(L,(const char *)result); SWIG_arg++;
lua_pushstring(L, (const char *)result);
SWIG_arg++;
return SWIG_arg;
fail: SWIGUNUSED;
fail:
SWIGUNUSED;
lua_error(L);
return 0;
}
@ -3243,7 +3169,8 @@ SWIG_PropagateClientData(void) {
#ifdef __cplusplus
#if 0
{ /* c-mode */
{
/* c-mode */
#endif
}
#endif
@ -3340,8 +3267,7 @@ SWIGEXPORT int SWIG_init(lua_State* L) /* default Lua action */
const char *SWIG_LUACODE =
"";
void SWIG_init_user(lua_State* L)
{
void SWIG_init_user(lua_State *L) {
/* exec Lua code if applicable */
SWIG_Lua_dostring(L, SWIG_LUACODE);
}

View file

@ -149,6 +149,7 @@ const static vocabulary_t vocabulary[] = {
{ 0, "hf 14a cuids" },
{ 0, "hf 14a info" },
{ 0, "hf 14a sim" },
{ 0, "hf 14a simaid" },
{ 0, "hf 14a sniff" },
{ 0, "hf 14a raw" },
{ 0, "hf 14a reader" },
@ -281,6 +282,7 @@ const static vocabulary_t vocabulary[] = {
{ 1, "hf iclass lookup" },
{ 0, "hf iclass legrec" },
{ 1, "hf iclass legbrute" },
{ 1, "hf iclass unhash" },
{ 0, "hf iclass sim" },
{ 0, "hf iclass eload" },
{ 0, "hf iclass esave" },
@ -674,6 +676,7 @@ const static vocabulary_t vocabulary[] = {
{ 0, "lf hitag hts reader" },
{ 0, "lf hitag hts rdbl" },
{ 0, "lf hitag hts wrbl" },
{ 0, "lf hitag hts sim" },
{ 1, "lf idteck help" },
{ 1, "lf idteck demod" },
{ 0, "lf idteck reader" },

View file

@ -1310,7 +1310,12 @@
"notes": [
"hf 14a raw -sc 3000 -> select, crc, where 3000 == 'read block 00'",
"hf 14a raw -ak -b 7 40 -> send 7 bit byte 0x40",
"hf 14a raw --ecp -s -> send ECP before select"
"hf 14a raw --ecp -s -> send ECP before select",
"Crypto1 session example, with special auth shortcut 6xxx<key>:",
"hf 14a raw --crypto1 -skc 6000FFFFFFFFFFFF",
"hf 14a raw --crypto1 -kc 3000",
"hf 14a raw --crypto1 -kc 6007FFFFFFFFFFFF",
"hf 14a raw --crypto1 -c 3007"
],
"offline": false,
"options": [
@ -1327,9 +1332,10 @@
"--ecp Use enhanced contactless polling",
"--mag Use Apple magsafe polling",
"--topaz Use Topaz protocol to send command",
"--crypto1 Use crypto1 session",
"<hex> Raw bytes to send"
],
"usage": "hf 14a raw [-hack3rsv] [-t <ms>] [-b <dec>] [--ecp] [--mag] [--topaz] <hex> [<hex>]..."
"usage": "hf 14a raw [-hack3rsv] [-t <ms>] [-b <dec>] [--ecp] [--mag] [--topaz] [--crypto1] <hex> [<hex>]..."
},
"hf 14a reader": {
"command": "hf 14a reader",
@ -1382,6 +1388,30 @@
],
"usage": "hf 14a sim [-hxv] -t <1-12> [-u <hex>] [-n <dec>] [--sk]"
},
"hf 14a simaid": {
"command": "hf 14a simaid",
"description": "Simulate ISO/IEC 14443 type A tag with 4,7 or 10 byte UID, and filter for AID Values These AID Values can be responded to and include extra APDU commands on GetData after response",
"notes": [
"hf 14a simaid -t 3 -> MIFARE Desfire",
"hf 14a simaid -t 4 -> ISO/IEC 14443-4",
"hf 14a simaid -t 11 -> Javacard (JCOP)",
"hf 14a simaid -t 3 --aid a000000000000000000000 --response 9000 --apdu 9000 -> AID, Response and APDU",
"hf 14a simaid -t 3 --rats 05788172220101 --response 01009000 --apdu 86009000 -> Custom RATS Added",
"hf 14a simaid -t 3 --rats 05788172220101 -x -> Enumerate AID Values"
],
"offline": false,
"options": [
"-h, --help This help",
"-t, --type <1-12> Simulation type to use",
"-u, --uid <hex> <4|7|10> hex bytes UID",
"-r, --rats <hex> <0-20> hex bytes RATS",
"-a, --aid <hex> <0-100> hex bytes for AID to respond to (Default: A000000000000000000000)",
"-e, --response <hex> <0-100> hex bytes for APDU Response to AID Select (Default: 9000)",
"-p, --apdu <hex> <0-100> hex bytes for APDU Response to Get Data request after AID (Default: 9000)",
"-x, --enumerate Enumerate all AID values via returning Not Found and print them to console"
],
"usage": "hf 14a simaid [-hx] -t <1-12> [-u <hex>] [-r <hex>] [-a <hex>] [-e <hex>] [-p <hex>]"
},
"hf 14a sniff": {
"command": "hf 14a sniff",
"description": "Sniff the communication between reader and tag Use `hf 14a list` to view collected data.",
@ -3377,7 +3407,7 @@
},
"hf iclass help": {
"command": "hf iclass help",
"description": "help This help list List iclass history view Display content from tag dump file ----------- --------------------- Recovery -------------------- loclass Use loclass to perform bruteforce reader attack lookup Uses authentication trace to check for key in dictionary file legbrute Bruteforces 40 bits of a partial raw key ----------- ---------------------- Utils ---------------------- calcnewkey Calc diversified keys (blocks 3 & 4) to write new keys encode Encode binary wiegand to block 7 encrypt Encrypt given block data decrypt Decrypt given block data or tag dump file managekeys Manage keys to use with iclass commands permutekey Permute function from 'heart of darkness' paper --------------------------------------------------------------------------------------- hf iclass list available offline: yes Alias of `trace list -t iclass -c` with selected protocol data to annotate trace buffer You can load a trace from file (see `trace load -h`) or it be downloaded from device by default It accepts all other arguments of `trace list`. Note that some might not be relevant for this specific protocol",
"description": "help This help list List iclass history view Display content from tag dump file ----------- --------------------- Recovery -------------------- loclass Use loclass to perform bruteforce reader attack lookup Uses authentication trace to check for key in dictionary file legbrute Bruteforces 40 bits of a partial diversified key, provided 24 bits of the key and two valid nr-macs unhash Reverses a diversified key to retrieve hash0 pre-images after DES encryption ----------- ---------------------- Utils ---------------------- calcnewkey Calc diversified keys (blocks 3 & 4) to write new keys encode Encode binary wiegand to block 7 encrypt Encrypt given block data decrypt Decrypt given block data or tag dump file managekeys Manage keys to use with iclass commands permutekey Permute function from 'heart of darkness' paper --------------------------------------------------------------------------------------- hf iclass list available offline: yes Alias of `trace list -t iclass -c` with selected protocol data to annotate trace buffer You can load a trace from file (see `trace load -h`) or it be downloaded from device by default It accepts all other arguments of `trace list`. Note that some might not be relevant for this specific protocol",
"notes": [
"hf iclass list --frame -> show frame delay times",
"hf iclass list -1 -> use trace buffer"
@ -3413,30 +3443,37 @@
"command": "hf iclass legbrute",
"description": "This command take sniffed trace data and partial raw key and bruteforces the remaining 40 bits of the raw key.",
"notes": [
"hf iclass legbrute --csn 8D7BD711FEFF12E0 --epurse feffffffffffffff --macs 00000000BD478F76 --pk B4F12AADC5301225"
"hf iclass legbrute --epurse feffffffffffffff --macs1 1306cad9b6c24466 --macs2 f0bf905e35f97923 --pk B4F12AADC5301225"
],
"offline": true,
"options": [
"-h, --help This help",
"--csn <hex> Specify CSN as 8 hex bytes",
"--epurse <hex> Specify ePurse as 8 hex bytes",
"--macs <hex> MACs",
"--pk <hex> Partial Key"
"--macs1 <hex> MACs captured from the reader",
"--macs2 <hex> MACs captured from the reader, different than the first set (with the same csn and epurse value)",
"--pk <hex> Partial Key from legrec or starting key of keyblock from legbrute",
"--index <dec> Where to start from to retrieve the key, default 0 - value in millions e.g. 1 is 1 million"
],
"usage": "hf iclass legbrute [-h] --csn <hex> --epurse <hex> --macs <hex> --pk <hex>"
"usage": "hf iclass legbrute [-h] --epurse <hex> --macs1 <hex> --macs2 <hex> --pk <hex> [--index <dec>]"
},
"hf iclass legrec": {
"command": "hf iclass legrec",
"description": "Attempts to recover the diversified key of a specific iClass card. This may take a long time. The Card must remain be on the PM3 antenna during the whole process! This process may brick the card!",
"notes": [
"hf iclass legrec --macs 0000000089cb984b"
"hf iclass legrec --macs 0000000089cb984b",
"hf iclass legrec --macs 0000000089cb984b --index 0 --loop 100 --notest"
],
"offline": false,
"options": [
"-h, --help This help",
"--macs <hex> MACs"
"--macs <hex> AA1 Authentication MACs",
"--index <dec> Where to start from to retrieve the key, default 0",
"--loop <dec> The number of key retrieval cycles to perform, max 10000, default 100",
"--debug Re-enables tracing for debugging. Limits cycles to 1.",
"--notest Perform real writes on the card!",
"--allnight Loops the loop for 10 times, recommended loop value of 5000."
],
"usage": "hf iclass legrec [-h] --macs <hex>"
"usage": "hf iclass legrec [-h] --macs <hex> [--index <dec>] [--loop <dec>] [--debug] [--notest] [--allnight]"
},
"hf iclass loclass": {
"command": "hf iclass loclass",
@ -3617,6 +3654,19 @@
],
"usage": "hf iclass sniff [-hj]"
},
"hf iclass unhash": {
"command": "hf iclass unhash",
"description": "Reverses the hash0 function used generate iclass diversified keys after DES encryption, returning the DES crypted CSN.",
"notes": [
"hf iclass unhash --divkey B4F12AADC5301A2D"
],
"offline": true,
"options": [
"-h, --help This help",
"--divkey <hex> The card's Diversified Key value"
],
"usage": "hf iclass unhash [-h] --divkey <hex>"
},
"hf iclass view": {
"command": "hf iclass view",
"description": "Print a iCLASS tag dump file (bin/eml/json)",
@ -9730,21 +9780,22 @@
"command": "lf hitag hts rdbl",
"description": "Read Hitag S memory. Crypto mode: - key format ISK high + ISK low - default key 4F4E4D494B52 (ONMIKR) 8268/8310 password mode: - default password BBDD3399",
"notes": [
"lf hitag hts rdbl -> Hitag S/8211, plain mode",
"lf hitag hts rdbl --82xx -k BBDD3399 -> 8268/8310, password mode",
"lf hitag hts rdbl --nrar 0102030411223344 -> Hitag S, challenge mode",
"lf hitag hts rdbl --crypto -> Hitag S, crypto mode, def key",
"lf hitag hts rdbl -k 4F4E4D494B52 -> Hitag S, crypto mode"
"lf hitag hts rdbl -p 1 -> Hitag S/8211, plain mode",
"lf hitag hts rdbl -p 1 --82xx -k BBDD3399 -> 8268/8310, password mode",
"lf hitag hts rdbl -p 1 --nrar 0102030411223344 -> Hitag S, challenge mode",
"lf hitag hts rdbl -p 1 --crypto -> Hitag S, crypto mode, def key",
"lf hitag hts rdbl -p 1 -k 4F4E4D494B52 -> Hitag S, crypto mode"
],
"offline": false,
"options": [
"-h, --help This help",
"--nrar <hex> nonce / answer writer, 8 hex bytes",
"-8, --82xx 8268/8310 mode",
"--nrar <hex> nonce / answer writer, 8 hex bytes",
"--crypto crypto mode",
"-k, --key <hex> pwd or key, 4 or 6 hex bytes"
"-k, --key <hex> pwd or key, 4 or 6 hex bytes",
"-p, --page <dec> page address to read from"
],
"usage": "lf hitag hts rdbl [-h8] [--nrar <hex>] [--crypto] [-k <hex>]"
"usage": "lf hitag hts rdbl [-h8] [--nrar <hex>] [--crypto] [-k <hex>] -p <dec>"
},
"lf hitag hts reader": {
"command": "lf hitag hts reader",
@ -9760,6 +9811,20 @@
],
"usage": "lf hitag hts reader [-h@]"
},
"lf hitag hts sim": {
"command": "lf hitag hts sim",
"description": "Simulate Hitag S transponder You need to `lf hitag hts eload` first",
"notes": [
"lf hitag hts sim",
"lf hitag hts sim --82xx"
],
"offline": false,
"options": [
"-h, --help This help",
"-8, --82xx simulate 8268/8310"
],
"usage": "lf hitag hts sim [-h8]"
},
"lf hitag hts wrbl": {
"command": "lf hitag hts wrbl",
"description": "Write a page in Hitag S memory. Crypto mode: - key format ISK high + ISK low - default key 4F4E4D494B52 (ONMIKR) 8268/8310 password mode: - default password BBDD3399",
@ -9773,8 +9838,8 @@
"offline": false,
"options": [
"-h, --help This help",
"--nrar <hex> nonce / answer writer, 8 hex bytes",
"-8, --82xx 8268/8310 mode",
"--nrar <hex> nonce / answer writer, 8 hex bytes",
"--crypto crypto mode",
"-k, --key <hex> pwd or key, 4 or 6 hex bytes",
"-p, --page <dec> page address to write to",
@ -9817,13 +9882,8 @@
},
"lf hitag read": {
"command": "lf hitag read",
"description": "Read Hitag memory. It support Hitag S and Hitag 2 Password mode: - default key 4D494B52 (MIKR) Crypto mode: - key format ISK high + ISK low - default key 4F4E4D494B52 (ONMIKR)",
"description": "Read Hitag memory. It support Hitag 2 Password mode: - default key 4D494B52 (MIKR) Crypto mode: - key format ISK high + ISK low - default key 4F4E4D494B52 (ONMIKR)",
"notes": [
"lf hitag read --hts -> Hitag S, plain mode",
"lf hitag read --hts --nrar 0102030411223344 -> Hitag S, challenge mode",
"lf hitag read --hts --crypto -> Hitag S, crypto mode, def key",
"lf hitag read --hts -k 4F4E4D494B52 -> Hitag S, crypto mode",
"",
"lf hitag read --ht2 --pwd -> Hitag 2, pwd mode, def key",
"lf hitag read --ht2 -k 4D494B52 -> Hitag 2, pwd mode",
"lf hitag read --ht2 --nrar 0102030411223344 -> Hitag 2, challenge mode",
@ -9833,14 +9893,13 @@
"offline": false,
"options": [
"-h, --help This help",
"-s, --hts Hitag S",
"-2, --ht2 Hitag 2",
"--pwd password mode",
"--nrar <hex> nonce / answer writer, 8 hex bytes",
"--crypto crypto mode",
"-k, --key <hex> key, 4 or 6 hex bytes"
],
"usage": "lf hitag read [-hs2] [--pwd] [--nrar <hex>] [--crypto] [-k <hex>]"
"usage": "lf hitag read [-h2] [--pwd] [--nrar <hex>] [--crypto] [-k <hex>]"
},
"lf hitag reader": {
"command": "lf hitag reader",
@ -9866,10 +9925,9 @@
"options": [
"-h, --help This help",
"-1, --ht1 simulate Hitag 1",
"-2, --ht2 simulate Hitag 2",
"-s, --hts simulate Hitag S"
"-2, --ht2 simulate Hitag 2"
],
"usage": "lf hitag sim [-h12s]"
"usage": "lf hitag sim [-h12]"
},
"lf hitag sniff": {
"command": "lf hitag sniff",
@ -9911,13 +9969,8 @@
},
"lf hitag wrbl": {
"command": "lf hitag wrbl",
"description": "Write a page in Hitag memory. It support HitagS and Hitag 2 Password mode: - default key 4D494B52 (MIKR) Crypto mode: - key format ISK high + ISK low - default key 4F4E4D494B52 (ONMIKR)",
"description": "Write a page in Hitag memory. It support Hitag 2 Password mode: - default key 4D494B52 (MIKR) Crypto mode: - key format ISK high + ISK low - default key 4F4E4D494B52 (ONMIKR)",
"notes": [
"lf hitag wrbl --hts -p 6 -d 01020304 -> HitagS, plain mode",
"lf hitag wrbl --hts -p 6 -d 01020304 --nrar 0102030411223344 -> HitagS, challenge mode",
"lf hitag wrbl --hts -p 6 -d 01020304 --crypto -> HitagS, crypto mode, def key",
"lf hitag wrbl --hts -p 6 -d 01020304 -k 4F4E4D494B52 -> HitagS, crypto mode",
"",
"lf hitag wrbl --ht2 -p 6 -d 01020304 --pwd -> Hitag 2, pwd mode, def key",
"lf hitag wrbl --ht2 -p 6 -d 01020304 -k 4D494B52 -> Hitag 2, pwd mode",
"lf hitag wrbl --ht2 -p 6 -d 01020304 --nrar 0102030411223344 -> Hitag 2, challenge mode",
@ -9927,7 +9980,6 @@
"offline": false,
"options": [
"-h, --help This help",
"-s, --hts Hitag S",
"-2, --ht2 Hitag 2",
"--pwd password mode",
"--nrar <hex> nonce / answer writer, 8 hex bytes",
@ -9936,7 +9988,7 @@
"-p, --page <dec> page address to write to",
"-d, --data <hex> data, 4 hex bytes"
],
"usage": "lf hitag wrbl [-hs2] [--pwd] [--nrar <hex>] [--crypto] [-k <hex>] -p <dec> -d <hex>"
"usage": "lf hitag wrbl [-h2] [--pwd] [--nrar <hex>] [--crypto] [-k <hex>] -p <dec> -d <hex>"
},
"lf idteck clone": {
"command": "lf idteck clone",
@ -12902,8 +12954,8 @@
}
},
"metadata": {
"commands_extracted": 745,
"commands_extracted": 747,
"extracted_by": "PM3Help2JSON v1.00",
"extracted_on": "2024-09-15T16:16:09"
"extracted_on": "2024-09-30T08:35:18"
}
}

View file

@ -192,6 +192,7 @@ Check column "offline" for their availability.
|`hf 14a cuids `|N |`Collect n>0 ISO14443-a UIDs in one go`
|`hf 14a info `|N |`Tag information`
|`hf 14a sim `|N |`Simulate ISO 14443-a tag`
|`hf 14a simaid `|N |`Simulate ISO 14443-a AID Selection`
|`hf 14a sniff `|N |`sniff ISO 14443-a traffic`
|`hf 14a raw `|N |`Send raw hex data to tag`
|`hf 14a reader `|N |`Act like an ISO14443-a reader`
@ -402,8 +403,9 @@ Check column "offline" for their availability.
|`hf iclass chk `|N |`Check keys`
|`hf iclass loclass `|Y |`Use loclass to perform bruteforce reader attack`
|`hf iclass lookup `|Y |`Uses authentication trace to check for key in dictionary file`
|`hf iclass legrec `|N |`Attempts to recover the standard key of a legacy card`
|`hf iclass legbrute `|Y |`Bruteforces 40 bits of a partial raw key`
|`hf iclass legrec `|N |`Recovers 24 bits of the diversified key of a legacy card provided a valid nr-mac combination`
|`hf iclass legbrute `|Y |`Bruteforces 40 bits of a partial diversified key, provided 24 bits of the key and two valid nr-macs`
|`hf iclass unhash `|Y |`Reverses a diversified key to retrieve hash0 pre-images after DES encryption`
|`hf iclass sim `|N |`Simulate iCLASS tag`
|`hf iclass eload `|N |`Upload file into emulator memory`
|`hf iclass esave `|N |`Save emulator memory to file`
@ -1078,6 +1080,7 @@ Check column "offline" for their availability.
|`lf hitag hts reader `|N |`Act like a Hitag S reader`
|`lf hitag hts rdbl `|N |`Read Hitag S memory`
|`lf hitag hts wrbl `|N |`Write Hitag S page`
|`lf hitag hts sim `|N |`Simulate Hitag transponder`
### lf idteck