Skip to content
Snippets Groups Projects
Select Git revision
  • 6e5634824d8d7c8a23e3f092aedacccd256c722f
  • master default protected
  • kirovets_doc
  • ypodlesov/unite-projection
  • max/parse-anonymous-blocks
  • sd/constant
  • docs/server_setup
  • ekhamitov/union-types
  • docs/privileges
  • sd/2244-issue
  • raiondesu/1984-used-tier-memory
  • lomakin/adr-client-bucket-awareness
  • lomakin/insert-query-sharding-metadata
  • 25.4 protected
  • ekhamitov/1977-remove-additional-child
  • gmoshkin/box-error-improvements
  • astrochuk/explain-fix
  • dkoltsov/support-https
  • docs/config_storage
  • ekhamitov/2365-fix-flaky
  • kostja-check-quorum
  • 25.4.4 protected
  • 25.3.8 protected
  • 25.3.7 protected
  • 25.4.3 protected
  • 25.3.6 protected
  • 25.4.2 protected
  • 25.3.5 protected
  • 25.4.1 protected
  • 25.5.0 protected
  • 25.3.4 protected
  • 25.3.3 protected
  • 25.3.2 protected
  • 25.4.0 protected
  • 25.3.1 protected
  • 25.2.4 protected
  • 25.2.3 protected
  • 25.2.2 protected
  • 25.2.1 protected
  • 25.3.0 protected
  • 25.1.2 protected
41 results

tarantool.rs

Blame
  • tarantool.rs 1.85 KiB
    use std::ffi::CStr;
    
    use tarantool::global_lua;
    use tarantool::tlua::{self, LuaFunction};
    
    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();
    }
    
    inventory::submit!(crate::InnerTest {
        name: "test_version",
        body: || {
            let l = global_lua();
            let t: tlua::LuaTable<_> = l.eval("return require('tarantool')").unwrap();
            assert_eq!(version(), t.get::<String, _>("version").unwrap());
            assert_eq!(package(), t.get::<String, _>("package").unwrap());
        }
    });
    
    #[derive(Clone, Debug, tlua::Push, tlua::LuaRead, PartialEq)]
    pub struct Cfg {
        pub listen: Option<String>,
        pub wal_dir: String,
        pub memtx_dir: String,
        pub feedback_enabled: bool,
    }
    
    impl Default for Cfg {
        fn default() -> Self {
            Self {
                listen: Some("3301".to_owned()),
                wal_dir: ".".to_owned(),
                memtx_dir: ".".to_owned(),
                feedback_enabled: false,
            }
        }
    }
    
    #[allow(dead_code)]
    pub fn cfg() -> Option<Cfg> {
        let l = global_lua();
        let cfg: Result<Cfg, _> = l.eval("return box.cfg");
        match cfg {
            Ok(v) => Some(v),
            Err(_) => None,
        }
    }
    
    pub fn set_cfg(cfg: &Cfg) {
        let l = global_lua();
        let box_cfg = LuaFunction::load(l, "return box.cfg(...)").unwrap();
        box_cfg.call_with_args(cfg).unwrap()
    }
    
    pub fn eval(code: &str) {
        let l = global_lua();
        let f = LuaFunction::load(l, code).unwrap();
        f.call().unwrap()
    }