C/C++ within Ruby code?

倖福魔咒の 提交于 2019-12-04 13:38:35

问题


C/C++ would be good option to write some of the performance critical aspects of a Ruby Application. I know this is possible.

I would like to know how to add C/C++ code into Ruby code; any other language for that matter.

Are there any practical applications of this which you noticed in open source projects or else?


回答1:


Besides "Extending Ruby", here are two other resources:

  • README.EXT (extension.rdoc) - shows you more about how to build C extensions. A good compliment to "Extending Ruby"
  • Ruby Inline - This is a library that tries to make it easier to build C extensions by having you call methods in ruby to compile C code.



回答2:


Look in the "Extending Ruby" section of the Pickaxe book:

http://www.ruby-doc.org/docs/ProgrammingRuby/html/ext_ruby.html




回答3:


you should have a look at SWIG - it allows you to create ruby extensions in C/C++.




回答4:


We use ffi in one of our projects.

Ruby-FFI is a ruby extension for programmatically loading dynamic libraries, binding functions within them, and calling those functions from Ruby code. Moreover, a Ruby-FFI extension works without changes on Ruby and JRuby.

It works quite well.




回答5:


Compile your high performance code into a system service/executable, and call it from inside Ruby...?




回答6:


Seems like you need to read up on Extending Ruby



来源:https://stackoverflow.com/questions/3250056/c-c-within-ruby-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!