~tim/scheme-vm

ref: ac6b8bca1104b34b18f766537d99fbc1be5c6b6b scheme-vm/src/lib.rs -rw-r--r-- 559 bytes
ac6b8bcaTim Morgan Playing around with ruby-sys 4 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
extern crate libc;
extern crate ruby_sys;

mod values;
mod tests;

mod lisp {
    include!(concat!(env!("OUT_DIR"), "/lisp.rs"));
}

#[no_mangle]
pub extern "C" fn is_ok(program_ptr: *const libc::c_char) -> i64 {
    let program = string_from_c_ptr(program_ptr);
    if lisp::program(&program).is_ok() {
        0x14
    } else {
        0
    }
}

fn string_from_c_ptr(c_ptr: *const libc::c_char) -> String {
    let c_str = unsafe {
        assert!(!c_ptr.is_null());
        std::ffi::CStr::from_ptr(c_ptr)
    };
    c_str.to_str().unwrap().to_string()
}