Skip to content

Commit

Permalink
Use Rake instead of Make
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan Scott Lewis committed Dec 19, 2012
1 parent 8d34941 commit d58989f
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 27 deletions.
15 changes: 0 additions & 15 deletions Makefile

This file was deleted.

2 changes: 2 additions & 0 deletions Rakefile
@@ -0,0 +1,2 @@
require_relative 'lib/rake/lua_mruby_tasks'
Rake::LuaMRubyTasks.new
23 changes: 11 additions & 12 deletions lib/lua-mruby.c
Expand Up @@ -7,17 +7,17 @@
#include "mruby/compile.h" #include "mruby/compile.h"


static int lua_mruby_run(lua_State *L) { static int lua_mruby_run(lua_State *L) {
// mrb_state *mrb = mrb_open(); mrb_state *mrb = mrb_open();
// const char *mrb_code = lua_tostring(L, 1); const char *mrb_code = lua_tostring(L, 1);
// struct mrb_parser_state* parser = mrb_parse_string(mrb, mrb_code, NULL); struct mrb_parser_state *p = mrb_parse_string(mrb, mrb_code, NULL);
// int mrb_generated_code = mrb_generate_code(mrb, parser->tree); int mrb_generated_code = mrb_generate_code(mrb, p-> tree);
//
// mrb_run( mrb, mrb_proc_new(mrb, mrb->irep[mrb_generated_code]), mrb_nil_value() ); mrb_run( mrb, mrb_proc_new(mrb, mrb->irep[mrb_generated_code]), mrb_nil_value() );
//
// int lua_return = mrb_generated_code > 0 ? 0 : 1; int lua_return = mrb_generated_code > 0 ? 0 : 1;
// lua_pushnumber(L, lua_return); lua_pushnumber(L, lua_return);
//
// mrb_close(mrb); mrb_close(mrb);


return 1; return 1;
} }
Expand All @@ -28,7 +28,6 @@ static const struct luaL_reg mrubylib[] = {
}; };


int luaopen_mruby(lua_State *L) { int luaopen_mruby(lua_State *L) {
// luaL_openlib(L, "mruby", mrubylib, 0);
luaL_register(L, "mruby", mrubylib); luaL_register(L, "mruby", mrubylib);
return 1; return 1;
} }
61 changes: 61 additions & 0 deletions lib/rake/lua_mruby_tasks.rb
@@ -0,0 +1,61 @@
require 'rake/tasklib'
require 'pathname'
Pathname.send(:alias_method, :/, :join)

class Rake::LuaMRubyTasks < Rake::TaskLib

def initialize

desc "Compile lua-mruby"
# task(:compile, &:compile)
task(:compile) { compile }

desc "Clean up the current build"
# task(:clean, &:clean)
task(:clean) { clean }

task :default => [:clean, :compile]

end

define_method(:root) { (Pathname.new(__FILE__) / '..' / '..' / '..').expand_path }
define_method(:compiler) { '/usr/bin/gcc' }
define_method(:mruby) { Pathname.new('/Users/ryguy/Code/C/Source/mruby') }
define_method(:lua) { Pathname.new('/usr/local/Cellar/lua/5.1.4') }
define_method(:mruby_include) { mruby / 'include' }
define_method(:mruby_src) { mruby / 'src' }
define_method(:lua_include) { lua / 'include' }
define_method(:package) { root / 'pkg' }
define_method(:output) { "-o #{package / 'mruby.so'}" }

def includes
[mruby_include, mruby_src, lua_include].collect { |path| "-I#{path}" }.join(' ')
end

def libraries
[
root / 'lib' / 'lua-mruby.c',
'-lm',
mruby / 'mrblib' / 'mrblib.o',
mruby / 'lib' / 'libmruby.a'
].join(' ')
end

def flags
'-llua -O3 -g -Wall -Werror-implicit-function-declaration -shared -O'
end

def command
[compiler, includes, flags, output, libraries].join(' ')
end

def compile
package.mkdir
system(command)
end

def clean
package.rmtree rescue nil
end

end

0 comments on commit d58989f

Please sign in to comment.