aboutsummaryrefslogtreecommitdiff
path: root/examples/hello_world.rs
blob: 24862f0aca7d2894f79a4b91685d8544f6ed5ea2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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);
    }
}