v / examples / hot_reload / message.v
32 lines · 28 sloc · 810 bytes · e475e9d437474979ee5725d19eaeccca7b168406
Raw
1module main
2
3// Build this example with `v -live message.v`
4import time
5import v.live
6
7struct App {
8mut:
9 x int
10 c int
11}
12
13@[live]
14fn print_message(mut app App) {
15 i := live.info()
16 println('Hello! Modify this message. OK reloads: ${i.reloads_ok:2d} | Total: ${i.reloads:2d} | app: ${voidptr(app)} | app.c: ${app.c:4} | app.x: ${app.x:12}')
17 // app.x = app.x * 3 + 1 // try changing this to another value, while the program is running ...
18 // app.x = 0
19 app.c++
20}
21
22fn main() {
23 unbuffer_stdout()
24 println('=============================================================')
25 println('== Modify the message below, while the program is running: ==')
26 println('=============================================================')
27 mut app := &App{}
28 for {
29 print_message(mut app)
30 time.sleep(500 * time.millisecond)
31 }
32}
33