From fb928e82a1dde92db62b5747e1006c5db2f752ca Mon Sep 17 00:00:00 2001 From: zeromus Date: Thu, 27 Jul 2017 23:44:08 -0500 Subject: [PATCH] fix fscanf (it was not working at all, reading from console by accident) --- KopiLua/src/luaconf.cs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/KopiLua/src/luaconf.cs b/KopiLua/src/luaconf.cs index e1951bc..528a2b1 100644 --- a/KopiLua/src/luaconf.cs +++ b/KopiLua/src/luaconf.cs @@ -1359,7 +1359,15 @@ public static Stream tmpfile() public static int fscanf(Stream f, CharPtr format, params object[] argp) { - string str = Console.ReadLine(); + StringBuilder sb = new StringBuilder(); + for (;;) + { + int c = f.ReadByte(); + if (c == -1) break; + if (c == '\n') break; //we should be transforming \r\n to \n before we get here, but that isn't done + sb.Append((char)c); + } + string str = sb.ToString(); return parse_scanf(str, format, argp); }