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)