Skip to content

Commit

Permalink
fix and cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
spytheman committed Jan 3, 2025
1 parent 4f8e4e6 commit 94b8810
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
8 changes: 3 additions & 5 deletions examples/hot_reload/message.v
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,10 @@ mut:

@[live]
fn print_message(mut app App) {
info := live.info()
println('1 OK reloads: ${info.reloads_ok:4d} | Total reloads: ${info.reloads:4d} | Hello! Modify this message while the program is running.')
eprintln('>> app: ${voidptr(app)} | g_live_reload_info: ${voidptr(g_live_reload_info)}')
app.x = 341 // try changing this to another value, while the program is running ...
i := live.info()
println('OK reloads: ${i.reloads_ok:4d} | Total reloads: ${i.reloads:4d} | ${voidptr(i)} Hello! Modify this message while the program is running. app: ${app}')
app.x = 2 // try changing this to another value, while the program is running ...
app.counter++
dump(app)
}

fn main() {
Expand Down
4 changes: 4 additions & 0 deletions vlib/v/gen/c/live.v
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ fn (mut g Gen) generate_hotcode_reloader_code() {
}
phd = windows_hotcode_definitions_1
}
// Ensure that g_live_reload_info from the executable is passed to the DLL/SO .
// See also vlib/v/live/sharedlib/live_sharedlib.v .
load_code << 'void (* fn_set_live_reload_pointer)(void *) = (void *)GetProcAddress(live_lib, "set_live_reload_pointer");'
load_code << 'if(fn_set_live_reload_pointer){ fn_set_live_reload_pointer( g_live_reload_info ); }'
g.hotcode_definitions.writeln(phd.replace('@LOAD_FNS@', load_code.join('\n')))
}
}
Expand Down
14 changes: 13 additions & 1 deletion vlib/v/live/sharedlib/live_sharedlib.v
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@ module sharedlib

import v.live as _

@[export: 'set_live_reload_pointer']
@[markused]
pub fn set_live_reload_pointer(p voidptr) {
eprintln('> set_live_reload_pointer, p: ${p}')
// NOTE: the `g_live_reload_info` global on windows, in the DLL, has a different address itself,
// compared to the g_live_reload_info in the main executable.
//
// The code here, ensures that *its value* will be the same,
// since the executable, will make sure to load the DLL, and then call set_live_reload_pointer()
// after binding it, in its generaged `v_bind_live_symbols`, with the value of its own `g_live_reload_info` global.
//
// This is not necessary on macos and linux, but it is best to have the same code across systems anyway.
// eprintln('>>>>> before &g_live_reload_info: ${voidptr(&g_live_reload_info)} | g_live_reload_info: ${voidptr(g_live_reload_info)}')
g_live_reload_info = p
// eprintln('>>>>> after &g_live_reload_info: ${voidptr(&g_live_reload_info)} | g_live_reload_info: ${voidptr(g_live_reload_info)}')
}

0 comments on commit 94b8810

Please sign in to comment.