]> git.ipfire.org Git - thirdparty/LuaJIT.git/commitdiff
Add compatibility string coercion for fp:seek() argument.
authorMike Pall <mike>
Sun, 9 Mar 2025 15:21:29 +0000 (16:21 +0100)
committerMike Pall <mike>
Sun, 9 Mar 2025 15:21:29 +0000 (16:21 +0100)
Reported by Magnus Wibeck. #1343

src/Makefile.dep
src/lib_io.c

index 9e14d6173600c42c65dbbffb311c53578b7e7f55..5b87d7c4521cc275c83594e923f92d95c7722564 100644 (file)
@@ -18,7 +18,7 @@ lib_ffi.o: lib_ffi.c lua.h luaconf.h lauxlib.h lualib.h lj_obj.h lj_def.h \
 lib_init.o: lib_init.c lua.h luaconf.h lauxlib.h lualib.h lj_arch.h
 lib_io.o: lib_io.c lua.h luaconf.h lauxlib.h lualib.h lj_obj.h lj_def.h \
  lj_arch.h lj_gc.h lj_err.h lj_errmsg.h lj_str.h lj_state.h lj_ff.h \
- lj_ffdef.h lj_lib.h lj_libdef.h
+ lj_ffdef.h lj_lib.h lj_strscan.h lj_libdef.h
 lib_jit.o: lib_jit.c lua.h luaconf.h lauxlib.h lualib.h lj_arch.h \
  lj_obj.h lj_def.h lj_err.h lj_errmsg.h lj_debug.h lj_str.h lj_tab.h \
  lj_bc.h lj_ir.h lj_jit.h lj_ircall.h lj_iropt.h lj_target.h \
index 6e330a73242137ef0e117b07bdc8d54a8a33d532..cb6df46d17111704a45f0e1e92f5d66e1be0ab12 100644 (file)
@@ -23,6 +23,7 @@
 #include "lj_state.h"
 #include "lj_ff.h"
 #include "lj_lib.h"
+#include "lj_strscan.h"
 
 /* Userdata payload for I/O file. */
 typedef struct IOFileUD {
@@ -324,13 +325,14 @@ LJLIB_CF(io_method_seek)
   FILE *fp = io_tofile(L)->fp;
   int opt = lj_lib_checkopt(L, 2, 1, "\3set\3cur\3end");
   int64_t ofs = 0;
-  cTValue *o;
+  TValue *o;
   int res;
   if (opt == 0) opt = SEEK_SET;
   else if (opt == 1) opt = SEEK_CUR;
   else if (opt == 2) opt = SEEK_END;
   o = L->base+2;
   if (o < L->top) {
+    if (tvisstr(o)) lj_strscan_num(strV(o), o);
     if (tvisint(o))
       ofs = (int64_t)intV(o);
     else if (tvisnum(o))