From a78015c28acbaa3eee514836ef2e69ded752c2d0 Mon Sep 17 00:00:00 2001
From: Yaroslav Dynnikov <yaroslav.dynnikov@gmail.com>
Date: Fri, 3 Dec 2021 16:17:04 +0300
Subject: [PATCH] Add draft of tarantool module

---
 picolib/lib.rs       | 11 ++++++++++-
 picolib/tarantool.rs | 22 ++++++++++++++++++++++
 2 files changed, 32 insertions(+), 1 deletion(-)
 create mode 100644 picolib/tarantool.rs

diff --git a/picolib/lib.rs b/picolib/lib.rs
index 2f879a62d4..9ff5425e2b 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 0000000000..575aab1504
--- /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();
+}
-- 
GitLab