git.s-ol.nu alive / 2403b5b
output to different streams at eval/runtime Close #13 s-ol 1 year, 9 months ago
4 changed file(s) with 21 addition(s) and 15 deletion(s). Raw diff Collapse all Expand all
295295 tick: =>
296296 if @inputs.value\metatype! == 'event'
297297 for msg in *@inputs.value!
298 print msg
298 L\print msg
299299 else
300 print @inputs.value!
300 L\print @inputs.value!
301301
302302 {
303303 :doc
4747 @root\tick_io!
4848 @root\tick!
4949 if not ok
50 print error
50 L\print error
5151 @registry\end_tick!
5252
5353 eval: =>
5454 @registry\begin_eval!
5555 ok, ast = Error.try "parsing '#{@file}'", program\match, slurp @file
5656 if not (ok and ast)
57 print ast or Error 'syntax', "failed to parse"
57 L\print ast or Error 'syntax', "failed to parse"
5858 @registry\rollback_eval!
5959 return
6060
6161 scope = Scope globals
6262 ok, root = Error.try "evaluating '#{@file}'", ast\eval, scope, @registry
6363 if not ok
64 print root
64 L\print root
6565 @registry\rollback_eval!
6666 return
6767
7575 return
7676
7777 if @last_modification < modification
78 L.stream = io.stderr
7879 L\log "#{@file} changed at #{modification}"
7980 @eval!
81 L.stream = io.stdout
8082 @last_modification = os.time!
8183
8284 {
3636 else
3737 error unpack res
3838
39 --- the stream to write to.
40 -- @tfield file stream
41
3942 --- static functions
4043 -- @section static
4144
4245 --- create a new Logger.
4346 -- @classmethod
4447 -- @tparam string level the log-level to log at.
45 new: (level='log') =>
48 -- @tparam file stream the stream to write to.
49 new: (level='log', @stream=io.stdout) =>
4650 @level = levels[level] or level
4751 @prefix = ''
4852
4953 for name, level in pairs levels
50 @[name] = (first, ...) =>
54 @[name] = (msg) =>
5155 return unless @level <= level
5256
53 where = debug.traceback '', 2
57 msg = tostring msg
58 @stream\write @prefix, msg, '\n'
5459 if level == levels.error or @level == levels.debug
55 print @prefix .. first, ...
56 print where
57 else
58 print @prefix .. first, ...
60 where = debug.traceback '', 2
61 @stream\write where, '\n'
62 @stream\flush!
5963
6064 if level == levels.print
6165 @push = (fn, ...) => fn ...
7377 -- - `'silent'`
7478 --
7579 -- @tparam ?string level the level to initialize the logger at.
80 -- @tparam ?file stream the output stream (stdout).
7681 @init: (...) ->
7782 L = Logger ...
7883
99
1010 cat > "$CONF" << 'EOF'
1111 split
12 screen -t evaltime sh -c 'tty > "$FIFO"; read done < "$FIFO"; screen -X quit'
1213 focus
13 screen -t evaltime sh -c 'tty > "$FIFO"; read done < "$FIFO"'
14 focus
15 screen -t runtime sh -c 'read tty < "$FIFO"; "alv" $ARGS 2> "$tty"; echo "[press enter to exit]"; read prompt; echo done > "$FIFO"'
14 screen -t runtime sh -c 'read tty < "$FIFO"; "alv" $ARGS 2> "$tty"; echo "[press enter to exit]"; read prompt; screen -X quit'
1615 EOF
1716
1817 mkfifo "$FIFO"