aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMelody Horn <melody@boringcactus.com>2021-05-14 22:05:20 -0600
committerMelody Horn <melody@boringcactus.com>2021-05-14 22:05:20 -0600
commit89308d5647629e797a034f16140d61d7e3f827e7 (patch)
tree5dc76f1c070ab2432bca29c7e0c1c6458c253693
parent167d83ca4521e7e604747142d2a2b79ecb3f7677 (diff)
downloadtcl-sys-89308d5647629e797a034f16140d61d7e3f827e7.tar.gz
tcl-sys-89308d5647629e797a034f16140d61d7e3f827e7.zip
add an example that should by all rights workHEADcanon
-rw-r--r--examples/hello_world.rs23
1 files changed, 23 insertions, 0 deletions
diff --git a/examples/hello_world.rs b/examples/hello_world.rs
new file mode 100644
index 0000000..24862f0
--- /dev/null
+++ b/examples/hello_world.rs
@@ -0,0 +1,23 @@
+use std::ffi::{CStr, CString};
+
+use tcl_sys::*;
+
+fn main() {
+ unsafe {
+ extract_stdlib_to(guess_expected_stdlib_target()).unwrap();
+ let interp = Tcl_CreateInterp();
+ let init_status = Tcl_Init(interp);
+ if init_status == TCL_ERROR as i32 {
+ eprintln!(
+ "{}",
+ CStr::from_ptr(Tcl_GetStringResult(interp)).to_string_lossy()
+ );
+ }
+ assert_eq!(init_status, TCL_OK as i32);
+ let script = CString::new(r#"puts "Hello, World!""#).unwrap();
+ let eval_status = Tcl_Eval(interp, script.as_ptr());
+ assert_eq!(eval_status, TCL_OK as i32);
+
+ Tcl_DeleteInterp(interp);
+ }
+}