From bf1f4b914b3481f40c08e3282f3ed614b11f8115 Mon Sep 17 00:00:00 2001 From: sealmove <47466000+sealmove@users.noreply.github.com> Date: Mon, 4 Mar 2019 11:52:34 +0200 Subject: [PATCH] Added optional proc parameter to llStreamOpenStdIn (#10769) --- compiler/llstream.nim | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/compiler/llstream.nim b/compiler/llstream.nim index e1108147f..8f57cda82 100644 --- a/compiler/llstream.nim +++ b/compiler/llstream.nim @@ -17,6 +17,7 @@ when not defined(windows) and (defined(useGnuReadline) or defined(useLinenoise)) import rdstdin type + TLLRepl* = proc (s: PLLStream, buf: pointer, bufLen: int): int TLLStreamKind* = enum # enum of different stream implementations llsNone, # null stream: reading and writing has no effect llsString, # stream encapsulates a string @@ -28,6 +29,7 @@ type s*: string rd*, wr*: int # for string streams lineOffset*: int # for fake stdin line numbers + repl*: TLLRepl # gives stdin control to clients PLLStream* = ref TLLStream @@ -50,11 +52,13 @@ proc llStreamOpen*(): PLLStream = new(result) result.kind = llsNone -proc llStreamOpenStdIn*(): PLLStream = +proc llReadFromStdin(s: PLLStream, buf: pointer, bufLen: int): int +proc llStreamOpenStdIn*(r: TLLRepl = llReadFromStdin): PLLStream = new(result) result.kind = llsStdIn result.s = "" result.lineOffset = -1 + result.repl = r proc llStreamClose*(s: PLLStream) = case s.kind @@ -127,7 +131,7 @@ proc llStreamRead*(s: PLLStream, buf: pointer, bufLen: int): int = of llsFile: result = readBuffer(s.f, buf, bufLen) of llsStdIn: - result = llReadFromStdin(s, buf, bufLen) + result = s.repl(s, buf, bufLen) proc llStreamReadLine*(s: PLLStream, line: var string): bool = setLen(line, 0)