rua 0.2.3-mswin32 → 0.2.4-mswin32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/README.txt +4 -0
  2. data/ext/rua.c +30 -5
  3. data/lib/i386-mswin32/rua.so +0 -0
  4. metadata +2 -2
data/README.txt CHANGED
@@ -32,6 +32,7 @@ http://rubyforge.org/frs/?group_id=4845
32
32
 
33
33
  rua.str = 'xxx'
34
34
  rua.num = 100
35
+ rua.range = 1..5
35
36
  rua.proc = lambda do
36
37
  puts 'proc called.'
37
38
  end
@@ -45,6 +46,9 @@ http://rubyforge.org/frs/?group_id=4845
45
46
  print('hello Rua!')
46
47
  print(str)
47
48
  print(num)
49
+ range.each(function(i)
50
+ print(i)
51
+ end)
48
52
  proc()
49
53
  err()
50
54
  print(Time.new().to_s())
data/ext/rua.c CHANGED
@@ -16,7 +16,7 @@ __declspec(dllexport) void Init_rua(void);
16
16
 
17
17
  #include "rua.h"
18
18
 
19
- #define VERSION "0.2.3"
19
+ #define VERSION "0.2.4"
20
20
  #define REF_RBOBJ "self"
21
21
 
22
22
  static const char *insecure_methods[] = {
@@ -686,7 +686,7 @@ static void rua_newtable_from_obj(lua_State *L, VALUE obj, struct rua_state *R)
686
686
 
687
687
  static int rua_proc_call(lua_State *L) {
688
688
  struct rua_state *R;
689
- VALUE proc, args, retval, errargs;
689
+ VALUE proc, args, last, retval, errargs;
690
690
  int i, n, status;
691
691
 
692
692
  proc = (VALUE) lua_touserdata(L, lua_upvalueindex(1));
@@ -698,8 +698,14 @@ static int rua_proc_call(lua_State *L) {
698
698
  rb_ary_push(args, rua_torbval(L, i + 1, R));
699
699
  }
700
700
 
701
+ last = (i > 0) ? rb_ary_entry(args, -1) : Qnil;
701
702
  rb_ary_push(args, proc);
702
- retval = rb_protect(_rua_proc_call, args, &status);
703
+
704
+ if (rb_obj_is_kind_of(last, RuaFunc)) {
705
+ retval = rb_protect(_rua_proc_call_with_block, args, &status);
706
+ } else {
707
+ retval = rb_protect(_rua_proc_call, args, &status);
708
+ }
703
709
 
704
710
  if (status != 0) {
705
711
  if (rua_obj_is_executable(R->error_handler)) {
@@ -721,9 +727,28 @@ static int rua_proc_call(lua_State *L) {
721
727
  }
722
728
 
723
729
  static VALUE _rua_proc_call(VALUE args) {
724
- VALUE proc = rb_ary_pop(args);
730
+ VALUE proc;
731
+
732
+ proc = rb_ary_pop(args);
733
+ return rb_funcall2(proc, rb_intern("call"), RARRAY(args)->len, RARRAY(args)->ptr);
734
+ }
735
+
725
736
 
726
- return rb_apply(proc, rb_intern("call"), args);
737
+ static VALUE _rua_proc_call_with_block(VALUE args) {
738
+ VALUE proc, block;
739
+
740
+ proc = rb_ary_pop(args);
741
+ block = rb_ary_pop(args);
742
+ rb_ary_push(args, proc);
743
+ return rb_iterate(_rua_proc_call, args, _rua_proc_call_as_block, block);
744
+ }
745
+
746
+ static VALUE _rua_proc_call_as_block(VALUE block_arg, VALUE block, VALUE self) {
747
+ if (TYPE(block_arg) == T_ARRAY) {
748
+ return rb_apply(block, rb_intern("call"), block_arg);
749
+ } else {
750
+ return rb_funcall(block, rb_intern("call"), 1, block_arg);
751
+ }
727
752
  }
728
753
 
729
754
  static VALUE rua_toruaobj(VALUE klass, lua_State *L, int idx, struct rua_state *R) {
Binary file
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.2
3
3
  specification_version: 1
4
4
  name: rua
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.2.3
7
- date: 2007-11-20 00:00:00 +09:00
6
+ version: 0.2.4
7
+ date: 2007-11-22 00:00:00 +09:00
8
8
  summary: Rua is a library for using Lua under Ruby.
9
9
  require_paths:
10
10
  - lib/i386-mswin32