Skip to content

Instantly share code, notes, and snippets.

@regonn
Created April 9, 2018 01:57
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 regonn/a91ebf6ef8c856d51dfd9a1380220cd5 to your computer and use it in GitHub Desktop.
Save regonn/a91ebf6ef8c856d51dfd9a1380220cd5 to your computer and use it in GitHub Desktop.
require 'fiddle'
require 'fiddle/import'
module Julia
extend Fiddle::Importer
# Linux
dlload Fiddle.dlopen('libjulia.so.0.6')
typealias "uint8_t", "unsigned char"
extern 'int jl_cpu_cores(void)'
extern 'void jl_init(void)'
extern 'jl_value_t *jl_eval_string(const char *str)'
extern 'void jl_atexit_hook(int status)'
extern 'uint8_t jl_unbox_uint8(jl_value_t *v)'
end
Julia.jl_init
puts "CPU: #{Julia.jl_cpu_cores}"
eval = Julia.jl_eval_string("1+1")
puts Julia.jl_unbox_uint8(eval)
Julia.jl_atexit_hook(0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment