Skip to content

Commit

Permalink
add initial implementation of ext library
Browse files Browse the repository at this point in the history
  • Loading branch information
yugui committed Sep 3, 2015
1 parent bc16a9c commit f62e9e7
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 1 deletion.
16 changes: 15 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
@@ -1,2 +1,16 @@
require "bundler/gem_tasks"
require 'bundler/gem_tasks'
require "rake/extensiontask"
require 'rake/testtask'

task :default => :compile

Rake::ExtensionTask.new do |t|
t.name = 'jsonnet_wrap'
t.ext_dir = 'ext/jsonnet'
t.lib_dir = 'lib/jsonnet'
end

Rake::TestTask.new('test' => 'compile') do |t|
t.libs << 'test'
t.verbose = true
end
2 changes: 2 additions & 0 deletions ext/jsonnet/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Makefile
*.o
6 changes: 6 additions & 0 deletions ext/jsonnet/extconf.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
require 'mkmf'

dir_config('jsonnet')
abort 'libjsonnet.h not found' unless have_header('libjsonnet.h')
abort 'libjsonnet not found' unless have_library('jsonnet')
create_makefile('jsonnet_wrap')
16 changes: 16 additions & 0 deletions ext/jsonnet/jsonnet.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include <ruby/ruby.h>
#include <libjsonnet.h>

static VALUE cVM;

static VALUE
jsonnet_s_version(VALUE mod) {
return rb_usascii_str_new_cstr(jsonnet_version());
}

void
Init_jsonnet_wrap(void) {
VALUE mJsonnet = rb_define_module("Jsonnet");
rb_define_singleton_method(mJsonnet, "libversion", jsonnet_s_version, 0);
cVM = rb_define_class_under(mJsonnet, "VM", rb_cData);
}
1 change: 1 addition & 0 deletions lib/jsonnet.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require "jsonnet/version"
require "jsonnet/jsonnet_wrap"

module Jsonnet
# Your code goes here...
Expand Down
8 changes: 8 additions & 0 deletions test/test_jsonnet.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
require 'jsonnet'
require 'test/unit'

class TestJsonnet < Test::Unit::TestCase
test 'libversion returns a String' do
assert_kind_of String, Jsonnet.libversion
end
end

0 comments on commit f62e9e7

Please sign in to comment.