FFI Python vs Ruby
Lately wrote about Python vs Ruby Singelton, this is a similar write up that is crips and talks about FFI in both of them.
FFI foreign function interface :
A foreign function interface (FFI) is a mechanism by which a program written in one programming language can call routines or make use of services written in another. Despite the name, FFIs are not necessarily restricted to function calls; many FFIs permit method calls on objects; and some even permit migration of non-trivial datatypes and/or objects across the language boundary.
FFI in Python to get the PID using C lib:
>>> import ctypes >>> libc = ctypes.CDLL("libc.dylib", ctypes.RTLD_GLOBAL) # On GNU/Linux '/lib/libc.so.6' >>> libc.getpid() 5516
FFI in Ruby to get the PID using C lib needs a gem install ffi:
require 'ffi' module GetPid extend FFI::Library attach_function :getpid, [], :uint end puts GetPid.getpid
This ends up in a draw? Or you see a clear winner? Well.. Left to your discretion.
Recent blog posts
- watir-webdriver web inspector
- gem list to gemfile
- Packing ruby2.0 on debian.
- Made it into The Guinness Book!
- to_h in ruby 2.0
- Filter elements by pattern jQuery.
- Better HTML password fields for mobile ?
- Grayscale image when user offline
- nth-child CSS pseudo-class Christmas colors
- EventEmitter in nodejs