Giter Site home page Giter Site logo

appsignal / c_from_ruby_example Goto Github PK

View Code? Open in Web Editor NEW
5.0 4.0 4.0 9 KB

Example to go with the Ruby Magic blog post.

Home Page: https://blog.appsignal.com/2018/10/30/ruby-magic-building-a-ruby-c-extension-from-scratch.html

License: MIT License

Ruby 80.11% Shell 1.56% C 18.33%

c_from_ruby_example's Introduction

CFromRubyExample

Example to go with the Ruby Magic blog post.

To hack on this run:

$ bin/setup
$ bin/rake compile

And then run this play around:

`$ bin/console
irb(main):001:0> CFromRubyExample::Helpers.string("a string")
=> "String from Ruby: 'a string'"
irb(main):002:0> CFromRubyExample::NativeHelpers.string("a string")
=> "String from C: 'a string'"
irb(main):003:0>

Or run the tests:

bin/rake test

c_from_ruby_example's People

Contributors

thijsc avatar tonidezman avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

c_from_ruby_example's Issues

Some questions regard your tutorial

Hi, Thank you for the great tutorial on creating ruby gem with c extension.
I have couple of questions hope you can help me to clear.

For rb_define_singleton_method(NativeHelpers, "string", string, 1);
I got the function definition as void rb_define_singleton_method(VALUE obj, const char *name, VALUE(*func)(ANYARGS), int argc);
May I ask is "string" for the name of function; and is string for type of input?

For rb_define_class_under(...), you create another class NativeHelpers under module CFromRubyExample; does this mean the class Helpers is obsolete(i.e. not necessary for the library anymore)? If class Helpers is obsolete, then what is point of attach_function :string, [:string], :string inside class Helpers extend FFI::Library block (e.g. nested class) ?

Thank you so much!

Running "rake" or "rake test" returns with error "File does not exist: extension"

After calling the commands in the README and confirming the extension can compile and works with the commands provided, I attempted to run the included tests. They didn't run, instead giving the error "File does not exist: extension". I see that "extension.bundle" is generated after compilation, in the "ext" directory. Is there something else it needs?

I'm using ruby 2.1.3p242 (2014-09-19 revision 47630) [x86_64-darwin17.0] on macOS Mojave, with the latest Xcode tools.

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.