Permalink
Browse files

0.1-0 release

  • Loading branch information...
1 parent 568b399 commit b8d28fd8f0329e187cd2c7a45c63d9c6df4f2e28 @RyanScottLewis committed Dec 24, 2012
Showing with 79 additions and 79 deletions.
  1. +0 −61 examples/sample.lua
  2. +7 −2 lib/lua-mruby.c
  3. +15 −5 lib/rake/lua_mruby_tasks.rb
  4. +1 −11 mruby-0.1-0.rockspec
  5. +56 −0 spec/mruby_spec.lua
View
61 examples/sample.lua
@@ -1,61 +0,0 @@
-require 'luarocks.require'
-require 'mruby'
-
-print(
- mruby.run(" puts 'Hello, World!' ") == 0
-)
-
-print('-=-=-=-=-=-=-==-=-=-=-=--=-=-')
-
-print(
- mruby.run('') == 0
-)
-
-print('-=-=-=-=-=-=-==-=-=-=-=--=-=-')
-
-print(
- mruby.run('asifbdbdsflbdslbaibidsabifabbsydifh') == 1
-)
-
-print('-=-=-=-=-=-=-==-=-=-=-=--=-=-')
-
-print(
- mruby.eval(" 'Hello, World!' ") == 'Hello, World!'
-)
-
-print('-=-=-=-=-=-=-==-=-=-=-=--=-=-')
-
-print(
- mruby.eval("123") == 123
-)
-
-print('-=-=-=-=-=-=-==-=-=-=-=--=-=-')
-
-print(
- mruby.eval("50 + 50") + 100 == 200
-)
-
-print('-=-=-=-=-=-=-==-=-=-=-=--=-=-')
-
-print(
- mruby.eval(" puts 'Hello, World!' ") == nil
-)
-
-print('-=-=-=-=-=-=-==-=-=-=-=--=-=-')
-
-print(
- mruby.eval(" 'Hello, ' ") .. 'World!' == 'Hello, World!'
-)
-
-
--- print(
--- mruby.run([[
--- sdlfjbnlsjdfbn
--- ]])
--- )
-
--- mrbState = mrbOpen()
--- print( mrbState ) -- Print out the MRuby state
--- print( mrbState:stack() ) -- Print out the MRuby state's stack
--- mrbClose()
---
View
9 lib/lua-mruby.c
@@ -188,8 +188,13 @@ int lua_mrb_eval(lua_State *L) {
// Check for exception
if (lua_mrb_state->exc) {
- p(lua_mrb_state, mrb_obj_value(lua_mrb_state->exc)); // Print exception (via Mruby #inspect)
- lua_mrb_state->exc = 0; // Reset exception flag
+ mrb_value lua_mrb_exception_value = mrb_obj_value(lua_mrb_state->exc);
+ mrb_value lua_mrb_exception_inspect_value = mrb_funcall(lua_mrb_state, lua_mrb_exception_value, "inspect", 0);
+
+ char *string_value = mrb_string_value_ptr(lua_mrb_state, lua_mrb_exception_inspect_value);
+ lua_pushstring(L, string_value);
+
+ lua_mrb_state->exc = 0; // Reset exception flag
} else {
lua_pushmrbvalue(L, lua_mrb_state, lua_mrb_result); // Pass the MRuby result to Lua
}
View
20 lib/rake/lua_mruby_tasks.rb
@@ -28,12 +28,17 @@ def initialize
desc "Clean up the current build"
task :clean => ['clean:lua', 'clean:mruby', 'clean:lua_mruby']
+ desc "Run specs"
+ task(:spec) { spec_lua_mruby }
+ task :test => :spec
+
task :default => [:clean, :compile]
end
define_method(:root) { (Pathname.new(__FILE__) / '..' / '..' / '..').expand_path }
define_method(:lib) { root / 'lib' }
+ define_method(:spec) { root / 'spec' }
define_method(:compiler) { '/usr/bin/gcc' }
define_method(:mruby) { lib / 'mruby' }
define_method(:lua) { lib / 'lua' }
@@ -71,11 +76,12 @@ def run(command)
def init_git
unless root.join('.git').exist?
- run "cd #{root} && git init"
- run "cd #{root} && git remote add origin https://github.com/RyanScottLewis/lua-mruby.git"
- run "cd #{root} && git pull origin master"
- run "cd #{root} && git submodule update --init lib/mruby/"
- run "cd #{root} && git submodule update --init lib/lua/"
+ run "cd #{root}"
+ run "git init"
+ run "git remote add origin https://github.com/RyanScottLewis/lua-mruby.git"
+ run "git pull origin master"
+ run "git submodule update --init lib/mruby/"
+ run "git submodule update --init lib/lua/"
end
end
@@ -107,4 +113,8 @@ def clean_lua_mruby
run "cd #{root} && rm -rf #{package / 'mruby.so*'}"
end
+ def spec_lua_mruby
+ run "tsc -f #{spec / '*_spec.lua'}"
+ end
+
end
View
12 mruby-0.1-0.rockspec
@@ -21,16 +21,6 @@ dependencies = {
}
build = {
type = "command",
- build_command = "ls -alRH && rake",
- -- modules = {
- -- lua_mruby = "lib/lua-mruby.c"
- -- -- lua_mruby = {
- -- -- sources = {"lib/lua-mruby.c"},
- -- -- -- -- defines = {"MAX_DATES_PER_MEAL=50"}
- -- -- -- -- libraries = {"date"},
- -- -- -- -- incdirs = {"$(LIBDATE_INCDIR)"},
- -- -- -- libdirs = {"lib"}
- -- -- }
- -- }
+ build_command = "ls -alRH && rake"
}
View
56 spec/mruby_spec.lua
@@ -0,0 +1,56 @@
+require "luarocks.require"
+require "telescope" -- https://github.com/norman/telescope
+require "lfs"
+
+package.cpath = package.cpath .. ";"..lfs.currentdir().."/pkg/mruby.so"
+require "mruby"
+
+context("mruby", function()
+
+ context(".run", function()
+
+ test("When valid code is given it should return 0", function()
+ assert_equal( mruby.run(""), 0)
+ assert_equal( mruby.run(" 10 + 10 "), 0)
+ assert_equal( mruby.run(" puts 'Hello, World!' "), 0)
+ end)
+
+ test("When invalid code is given it should return 1", function()
+ assert_equal( mruby.run(" foo "), 1)
+ assert_equal( mruby.run(" 10 + 'hello' "), 1)
+ end)
+
+ end)
+
+ context(".eval", function()
+
+ test("When valid code is given it should return the MRuby object converted into a Lua object", function()
+ assert_equal( mruby.eval(" 'Hello, World!' "), "Hello, World!")
+ assert_equal( mruby.eval(" 123 "), 123)
+ assert_equal( mruby.eval(" 50 + 50 ") + 100, 200)
+ assert_equal( mruby.eval(" puts 'Hello, World!' "), nil)
+ assert_equal( mruby.eval(" 'Hello, ' ").."World!", "Hello, World!")
+ end)
+
+ -- FIXME: in 0.1-1 : Should have more elegant way of capturing errors...
+ test("When invalid code is given it should return exception as a string", function()
+ assert_equal( mruby.eval(" foo "), "NoMethodError: undefined method 'foo' for main")
+ assert_equal( mruby.eval(" 10 + 'hello' "), "TypeError: non float value")
+ end)
+
+ end)
+
+end)
+
+
+-- print(
+-- mruby.run([[
+-- sdlfjbnlsjdfbn
+-- ]])
+-- )
+
+-- mrbState = mrbOpen()
+-- print( mrbState ) -- Print out the MRuby state
+-- print( mrbState:stack() ) -- Print out the MRuby state's stack
+-- mrbClose()
+--

0 comments on commit b8d28fd

Please sign in to comment.