Sha256: 2032406d8b8774b91061f7bdd4c5987987f5f74594e873987e3092366ddec098

Contents?: true

Size: 870 Bytes

Versions: 1

Compression:

Stored size: 870 Bytes

Contents

use ruru::{AnyObject, Array, Object};
use ruru::types::{Argc, Value, CallbackPtr};
use ruru::util::str_to_cstring;
extern crate ruby_sys;
use self::ruby_sys::{class, util};
use ::pathname;

pub type ValueCallback<I, O> = extern "C" fn(Argc, *const Value, I) -> O;

pub fn define_singleton_method<I: Object, O: Object>(
    klass: Value,
    name: &str,
    callback: ValueCallback<I, O>,
) {
    let name = str_to_cstring(name);

    unsafe {
        class::rb_define_singleton_method(klass, name.as_ptr(), callback as CallbackPtr, -1);
    }
}

// ruru doesn't support splat arguments yet
pub extern fn pub_join(argc: Argc, argv: *const Value, _: AnyObject) -> AnyObject {
  let args = Value::from(0);

  unsafe {
    util::rb_scan_args(
      argc,
      argv,
      str_to_cstring("*").as_ptr(),
      &args
    )
  };
  
  pathname::pn_join(Ok(Array::from(args)))
}

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
faster_path-0.2.5 src/pathname_sys.rs