-
-
Save maxdemarzi/8652c7cf3aedfad558c18aaa2a468242 to your computer and use it in GitHub Desktop.
Calling Julia from LuaJIT via a shared library
This file contains hidden or 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
ffi = require("ffi") | |
julia = ffi.load("/Users/inorton/git/julia/usr/lib/libjulia.dylib", true) | |
ffi.cdef[[ | |
void jl_eval_string(const char*); | |
void jl_init(const char*); | |
]] | |
julia.jl_init("/Users/inorton/git/julia/usr/lib/") | |
julia.jl_eval_string(" println(\"hello, world\") ") | |
-- should print "hello, world" |
This file contains hidden or 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
#include "julia.h" | |
int | |
loadjl(char* path) | |
{ | |
jl_init(path); | |
JL_SET_STACK_BASE; | |
jl_eval_string("println(sqrt(2.0))"); | |
return 0; | |
} |
This file contains hidden or 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
local ffi = require("ffi") | |
local test = ffi.load("./test.so", true) -- note the optional second argument means to load symbols globally | |
ffi.cdef[[ | |
void loadjl(char*); | |
]] | |
local path = ffi.new("char[19]", "/cmn/jldev/usr/bin") | |
test.loadjl(path) |
This file contains hidden or 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
gcc -o test.so -I$JULIA_DIR/src -I$JULIA_DIR/src/support -I$JULIA_DIR/usr/include -L$JULIA_DIR/usr/lib -fPIC -shared test.c -ljulia-debug |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment