Skip to content

Commit

Permalink
more cleanup, fix compilation on posix (use dlsym)
Browse files Browse the repository at this point in the history
  • Loading branch information
spytheman committed Jan 3, 2025
1 parent 94b8810 commit aa16e41
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
4 changes: 2 additions & 2 deletions examples/hot_reload/message.v
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ mut:
@[live]
fn print_message(mut app App) {
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 ...
println('OK reloads: ${i.reloads_ok:4d} | Total reloads: ${i.reloads:4d} | Hello! Modify this message while the program is running. app: ${voidptr(app)} | app.x: ${app.x:6} | app.counter: ${app.counter:6}')
// app.x = 99 // try changing this to another value, while the program is running ...
app.counter++
}

Expand Down
6 changes: 4 additions & 2 deletions vlib/v/gen/c/live.v
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,19 @@ fn (mut g Gen) generate_hotcode_reloader_code() {
for so_fn in g.hotcode_fn_names {
load_code << '\timpl_live_${so_fn} = dlsym(live_lib, "impl_live_${so_fn}");'
}
load_code << 'void (* fn_set_live_reload_pointer)(void *) = (void *)dlsym(live_lib, "set_live_reload_pointer");'
phd = posix_hotcode_definitions_1
} else {
for so_fn in g.hotcode_fn_names {
load_code << '\timpl_live_${so_fn} = (void *)GetProcAddress(live_lib, "impl_live_${so_fn}"); '
}
load_code << 'void (* fn_set_live_reload_pointer)(void *) = (void *)GetProcAddress(live_lib, "set_live_reload_pointer");'
phd = windows_hotcode_definitions_1
}
// Ensure that g_live_reload_info from the executable is passed to the DLL/SO .
// Ensure that g_live_reload_info from the executable is passed to the DLL .
// 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

0 comments on commit aa16e41

Please sign in to comment.