Created
June 5, 2019 17:35
-
-
Save gr33n7007h/0ac6b4f12623749491d20d79455cb772 to your computer and use it in GitHub Desktop.
Run Ruby from LuaJIT
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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