diff --git a/picolib/lib.rs b/picolib/lib.rs index 2f879a62d4f004ac82b8b406ac57b68422561d38..9ff5425e2ba6a5e18455e883408a69a2928f4958 100644 --- a/picolib/lib.rs +++ b/picolib/lib.rs @@ -1,12 +1,21 @@ use std::os::raw::c_int; +mod tarantool; #[no_mangle] pub extern "C" fn luaopen_picolib(_l: std::ffi::c_void) -> c_int { - println!("Hello from rust lib"); for (key, value) in std::env::vars() { if key.starts_with("PICODATA_") { println!("{}: {}", key, value); } } + + println!(); + println!("Hello from Rust {}", std::module_path!()); + println!( + "Running on {} {}", + tarantool::package(), + tarantool::version() + ); + 0 } diff --git a/picolib/tarantool.rs b/picolib/tarantool.rs new file mode 100644 index 0000000000000000000000000000000000000000..575aab150451f6e4280fb8e5dc0d89fd7956c6a6 --- /dev/null +++ b/picolib/tarantool.rs @@ -0,0 +1,22 @@ +use std::ffi::CStr; + +mod ffi { + use libc::c_char; + + extern "C" { + pub fn tarantool_version() -> *const c_char; + pub fn tarantool_package() -> *const c_char; + } +} + +pub fn version() -> &'static str { + let c_ptr = unsafe { ffi::tarantool_version() }; + let c_str = unsafe { CStr::from_ptr(c_ptr) }; + return c_str.to_str().unwrap(); +} + +pub fn package() -> &'static str { + let c_ptr = unsafe { ffi::tarantool_package() }; + let c_str = unsafe { CStr::from_ptr(c_ptr) }; + return c_str.to_str().unwrap(); +}