Giter Club home page Giter Club logo

binder's Introduction

BindER -- Binder Environment for Ruby with C++

  • C++14
  • bind support for mruby only yet.
  • just put 'bindenvruby.h' to your project and include it

Easy Guide

  • mruby
// call binder
auto binder_mruby(mrb_state* mruby) {
    int random_data = 0;
    auto binder = BindER::ruby_binder(mruby);
    {
        // ctor
        auto foobinder = binder.bind_class("Foo", [](int a, int b) {
            return new(std::nothrow) Foo(a+b);
        });
        // first argument is binded-class pointer -> instance-method
        foobinder.bind("bar", [](Foo* obj, int a, int b, int c) noexcept { return obj->bar(a, b, c); });
        // first argument NOT binded-class pointer -> class-method
        foobinder.bind("baz", [](int b) noexcept { return Foo::baz(b, 5, 7); });
        // limited lambda working(do not capture value-passed-custom-type-object because of static lambda)
        foobinder.bind("baa", [&]() noexcept { return Foo::baz(random_data, 5, 7); });
        // // return first parameter given
        foobinder.bind("foo=", [](Foo* obj, Foo2* f2) noexcept { 
            obj->set_foo(f2); return BindER::original_parameter<0>();
        });
    }
}
  • more codes, refer to files under folder test

Performance(In MSC)

when noinline when inline

Custom Type Support

  • search ADD YOUR OWN TYPE HERE
  • add your own type
  • for example with std::string
  // mruby arg to c++: for std::string
  template<> struct ruby_arg<std::string> {
      // get, hope RVO working
      static auto get(const mrb_value& v) noexcept { return std::string(RSTRING_PTR(v)); }
      // set mruby
      template<typename Lam>
      static auto set(mrb_state* ms, Lam lam) noexcept { return ::mrb_str_new_cstr(ms, lam().c_str()); }
  };
  // mruby arg to c++: for std::string&, same with std::string
  template<> struct ruby_arg<std::string&> :  ruby_arg<std::string> { };
  // mruby arg to c++: for const std::string&, same with std::string&
  template<> struct ruby_arg<const std::string&> :  ruby_arg<std::string&> { };

License

MIT or WTFPL, refer to License-MIT.txt or License-WTFPL.txt please

binder's People

Contributors

dustpg avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.