Talks
Speakers
Events
Topics
Sign in
Home
Talks
Speakers
Events
Topics
Leaderboard
Use
Analytics
Sign in
Suggest modification to this talk
Title
Description
Ruby is a flexible language that allows us to write expressive and maintainable code. However, sometimes it could be necessary to work with a low-level language, looking for better performance. In this talk, I’m going to show you how to use Ruby to create an interface for compiled languages like C.
Date
Summarized using AI?
If this talk's summary was generated by AI, please check this box. A "Summarized using AI" badge will be displayed in the summary tab to indicate that the summary was generated using AI.
Show "Summarized using AI" badge on summary page
Summary
Markdown supported
In the video "Going Native with FFI," presented by Juan Carlos Ruiz at Euruko 2021, the speaker discusses how Ruby, while a flexible programming language, can be enhanced by integrating with low-level languages like C for improved performance. Ruiz, a software engineer and mentor, highlights the advantages of using Ruby together with C, outlining various methods to create interfaces between the two. He elaborates on two primary approaches: MKMF and FFI (Foreign Function Interface). **Key Points Discussed:** - **Introduction to Juan Carlos Ruiz:** - Ruiz's background and work with Easy Broker, his passion for open-source projects, and his history with Ruby and C. - **Using MKMF:** - MKMF generates makefiles for Ruby C extensions, enabling the compilation and linking of C code to Ruby. - The process involves wrapping C functions in Ruby, allowing Ruby modules to use these functions. - Example: Ruiz demonstrates with a small C extension that includes a simple function to print greetings and calculate squares, showing how these functions can be called from Ruby. - **Adopting FFI:** - FFI allows Ruby to call functions from C libraries directly without the need for additional C code or detailed bindings. - This method is multi-platform compatible and less complex. However, it might be challenging to maintain for more intricate C macros. - Ruiz gives an example of using FFI to manipulate PGM (Portable Gray Map) images, outlining the steps for implementing image inversion functionality through a C library. - **Examples Demonstrated:** - In the demonstration, Ruiz loads a PGM image, calls functions to invert colors, and saves the modified image using the Ruby interface tied to the C code. **Conclusions and Takeaways:** - The choice between MKMF and FFI depends on the project requirements: - Use MKMF for greater control over C code or when wrapping smaller libraries. - Opt for FFI for ease of use, especially in multi-platform projects where you want to avoid writing extensive C code. - Ruiz encourages viewers to access his GitHub for the code examples shared during the talk and invites them to reach out for further discussions.
Suggest modifications
Cancel