mirror of https://gitlab.com/slondr/rust-guile.git
clean up code and rewrite C glue in Rust
This commit is contained in:
parent
c8729ef133
commit
7fa93b646f
|
@ -10,7 +10,4 @@ void load_guile() {
|
|||
scm_with_guile(®ister_functions, 0);
|
||||
}
|
||||
|
||||
void run_scm(int argc, char ** argv) {
|
||||
scm_shell(argc, argv);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,9 +1,3 @@
|
|||
#pragma once
|
||||
|
||||
#include <libguile.h>
|
||||
|
||||
static void * register_functions(void * data);
|
||||
|
||||
void load_guile();
|
||||
|
||||
void run_scm(int argc, char ** argv);
|
||||
|
|
|
@ -18995,12 +18995,6 @@ extern "C" {
|
|||
extern "C" {
|
||||
pub fn scm_i_init_deprecated();
|
||||
}
|
||||
extern "C" {
|
||||
pub fn load_guile();
|
||||
}
|
||||
extern "C" {
|
||||
pub fn run_scm(argc: ::std::os::raw::c_int, argv: *mut *mut ::std::os::raw::c_char);
|
||||
}
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct __locale_data {
|
||||
|
|
20
src/main.rs
20
src/main.rs
|
@ -9,13 +9,24 @@ use std::ffi::CStr;
|
|||
|
||||
include!("./bindings.rs");
|
||||
|
||||
#[no_mangle]
|
||||
extern "C" fn register_functions(_data: *mut c_void) -> *mut c_void {
|
||||
// right now this function does nothing
|
||||
// however, we need it for scm_with_guile()
|
||||
let ret: *mut c_void = std::ptr::null_mut();
|
||||
ret
|
||||
}
|
||||
|
||||
unsafe extern "C" fn init_scm() {
|
||||
// this function launches the scheme process and starts bootstrapping the runtime
|
||||
// any code executed after this function but before `scm_shell()' can talk to the scheme runtime
|
||||
scm_with_guile(Some(register_functions), std::ptr::null_mut());
|
||||
}
|
||||
|
||||
unsafe extern "C" fn hello_from_rust() -> SCM {
|
||||
println!("Hello from Rust!");
|
||||
scm_from_int8(0)
|
||||
}
|
||||
|
||||
|
||||
fn main() {
|
||||
let mut args = std::env::args().map(|mut arg| arg.as_mut_ptr() as *mut c_char ).collect::<Vec<*mut c_char>>();
|
||||
|
||||
|
@ -27,12 +38,9 @@ fn main() {
|
|||
let hello: *mut c_void = hello_from_rust as *mut c_void;
|
||||
|
||||
let fn_name: *const c_char = CStr::from_bytes_with_nul(b"hello_from_rust\0").unwrap().as_ptr();
|
||||
|
||||
|
||||
println!("launching scheme");
|
||||
|
||||
load_guile();
|
||||
scm_c_define_gsubr(fn_name, 0 as c_int, 0 as c_int, 0 as c_int, hello);
|
||||
run_scm(argc, c_args);
|
||||
scm_shell(argc, c_args);
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue