Use standard number coercion for file:seek. #1343

Code by @Buristan.
This commit is contained in:
Magnus Wibeck 2025-02-13 17:08:30 +01:00
parent a4f56a459a
commit a582f1a262

View File

@ -329,14 +329,8 @@ LJLIB_CF(io_method_seek)
else if (opt == 1) opt = SEEK_CUR; else if (opt == 1) opt = SEEK_CUR;
else if (opt == 2) opt = SEEK_END; else if (opt == 2) opt = SEEK_END;
o = L->base+2; o = L->base+2;
if (o < L->top) { if (o < L->top && !tvisnil(o))
if (tvisint(o)) ofs = (int64_t)lj_lib_checknum(L, 3);
ofs = (int64_t)intV(o);
else if (tvisnum(o))
ofs = (int64_t)numV(o);
else if (!tvisnil(o))
lj_err_argt(L, 3, LUA_TNUMBER);
}
#if LJ_TARGET_POSIX #if LJ_TARGET_POSIX
res = fseeko(fp, ofs, opt); res = fseeko(fp, ofs, opt);
#elif _MSC_VER >= 1400 #elif _MSC_VER >= 1400