Skip to content

Instantly share code, notes, and snippets.

@gr33n7007h
Created June 5, 2019 17:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gr33n7007h/0ac6b4f12623749491d20d79455cb772 to your computer and use it in GitHub Desktop.
Save gr33n7007h/0ac6b4f12623749491d20d79455cb772 to your computer and use it in GitHub Desktop.
Run Ruby from LuaJIT
#!/usr/bin/env luajit
local ffi = require 'ffi'
local cast = ffi.cast
local cdef = ffi.cdef
local load = ffi.load
local libruby = load '/usr/lib/libruby.so'
cdef[[
typedef unsigned long VALUE;
void ruby_init(void);
VALUE rb_eval_string(const char *);
int ruby_cleanup(volatile int ex);
]]
local rbcode = cast('char *', 'puts (1..20).inject(:lcm)')
libruby.ruby_init()
libruby.rb_eval_string(rbcode)
libruby.ruby_cleanup(0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment