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 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
#![allow(non_snake_case)] extern crate libc; pub enum StructWrenVM { } pub type WrenVM = StructWrenVM; pub type WrenReallocateFn = ::std::option::Option<extern "C" fn (memory: *mut ::libc::c_void, oldSize: ::libc::size_t, newSize: ::libc::size_t) -> *mut ::libc::c_void>; pub type WrenForeignMethodFn = ::std::option::Option<extern "C" fn(vm: *mut WrenVM)>; pub type WrenLoadModuleFn = extern "C" fn(vm: *mut WrenVM, name: *const ::libc::c_char) -> *const ::libc::c_char; #[repr(C)] pub struct Struct_Unnamed1 { pub reallocateFn: WrenReallocateFn, pub loadModuleFn: WrenLoadModuleFn, pub initialHeapSize: ::libc::size_t, pub minHeapSize: ::libc::size_t, pub heapGrowthPercent: ::libc::c_int, } impl ::std::default::Default for Struct_Unnamed1 { fn default() -> Struct_Unnamed1 { unsafe { ::std::mem::zeroed() } } } pub type WrenConfiguration = Struct_Unnamed1; pub type EnumUnnamed2 = ::libc::c_uint; pub const WREN_RESULT_SUCCESS: ::libc::c_uint = 0; pub const WREN_RESULT_COMPILE_ERROR: ::libc::c_uint = 1; pub const WREN_RESULT_RUNTIME_ERROR: ::libc::c_uint = 2; pub type WrenInterpretResult = EnumUnnamed2; extern "C" { pub fn wrenNewVM(configuration: *mut WrenConfiguration) -> *mut WrenVM; pub fn wrenFreeVM(vm: *mut WrenVM); pub fn wrenInterpret(vm: *mut WrenVM, sourcePath: *const ::libc::c_char, source: *const ::libc::c_char) -> WrenInterpretResult; pub fn wrenDefineMethod(vm: *mut WrenVM, className: *const ::libc::c_char, methodName: *const ::libc::c_char, numParams: ::libc::c_int, method: WrenForeignMethodFn); pub fn wrenDefineStaticMethod(vm: *mut WrenVM, className: *const ::libc::c_char, methodName: *const ::libc::c_char, numParams: ::libc::c_int, method: WrenForeignMethodFn); pub fn wrenGetArgumentDouble(vm: *mut WrenVM, index: ::libc::c_int) -> ::libc::c_double; pub fn wrenGetArgumentString(vm: *mut WrenVM, index: ::libc::c_int) -> *const ::libc::c_char; pub fn wrenReturnDouble(vm: *mut WrenVM, value: ::libc::c_double); pub fn wrenReturnNull(vm: *mut WrenVM); pub fn wrenReturnString(vm: *mut WrenVM, text: *const ::libc::c_char, length: ::libc::c_int); } #[cfg(test)] mod test { use std::default::Default; use super::{wrenNewVM, WrenConfiguration, wrenInterpret, wrenFreeVM, WREN_RESULT_SUCCESS, }; use std::ffi::CString; #[test] fn test_new_vm() { unsafe { let mut config: WrenConfiguration = Default::default(); let vm = wrenNewVM(&mut config); let source_path = CString::new("").unwrap().as_ptr(); let source = CString::new(r#" class Unicorn { hasHorn { return true } } "#).unwrap().as_ptr(); let result = wrenInterpret(vm, source_path, source); assert_eq!(result, WREN_RESULT_SUCCESS); wrenFreeVM(vm); } } }