New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to use set_variable
?
#133
Comments
// set the global to all windows
if let Err(e) = sciter::set_variable("svglobal", Value::from("hello, globals")) {
// ignore this
eprintln!("sciter.set_variable: {:?}", e);
}
frame.load_html(html, Some("example://minimal.htm"));
// set the global only for this window
if let Err(e) = frame.set_variable("svdocument", Value::from("hello, document")) {
eprintln!("frame.set_variable: {:?}", e);
} globalThis.svdocument;
globalThis.svglobal; Also, ignore the first error: https://sciter.com/forums/topic/hruntimeset_global_variable-always-returns-false/ |
And get: println!("document: {:?}", frame.get_variable("svglobal"));
println!("document: {:?}", frame.get_variable("svdocument"));
println!("location: {:?}", frame.get_variable("location"));
// doesn't work:
println!("Window.this: {:?}", frame.get_variable("Window.this")); |
Keep in mind that this API was introduced (yet disabled) in Sciter 4.4.4.6. but properly enabled only in 4.4.8.26. |
Tried doing as you suggested. No luck. sciter::set_library("./lib/libsciter-gtk.so").expect("Invalid library path.");
println!("Version: {:?}", sciter::version());
let mut frame = sciter::Window::new();
// let mut root = frame.get_host().get_root().expect("hello");
// set the global to all windows
if let Err(e) = sciter::set_variable("svglobal", Value::from("hello, globals")) {
// ignore this
eprintln!("sciter.set_variable: {:?}", e);
}
frame.load_file("./host/main.htm");
// set the global only for this window
if let Err(e) = frame.set_variable("svdocument", Value::from("hello, document")) {
eprintln!("frame.set_variable: {:?}", e);
}
println!("document: {:?}", frame.get_variable("svglobal"));
println!("document: {:?}", frame.get_variable("svdocument"));
println!("location: {:?}", frame.get_variable("location"));
frame.run_app(); Result:
The JS part: console.log("HELLO!", globalThis.svdocument, globalThis.svglobal); Edit: oh wait. From the output, i can see the variables are getting set after the initialization. Let me put this into an event handler. |
Well, on Windows |
No, it's sync everywhere. The This is a good use case for the |
Okay, didn't work. No idea why this is resulting in an error. // set the global only for this window
if let Err(e) = frame.set_variable("svdocument", Value::from("hello, document")) {
eprintln!("frame.set_variable: {:?}", e);
} Any way to see the error message? |
Well, it does print something like "frame.set_variable: INVALID_PARAMETER". Nothing more: https://github.com/c-smile/sciter-js-sdk/blob/main/include/sciter-x-dom.h#L59-L79 |
I tried doing this:
But I don't know how to retrieve the set variable.
Window.this.hello
andglobalThis.hello
both return undefined. Evenget_variable
returns undefined.The text was updated successfully, but these errors were encountered: