rua 0.3.0-mswin32 → 0.3.1-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 +43 -4
  3. data/lib/i386-mswin32/rua.so +0 -0
  4. metadata +2 -2
data/README.txt CHANGED
@@ -18,6 +18,8 @@ gem install rua
18
18
 
19
19
  http://rubyforge.org/frs/?group_id=4845
20
20
 
21
+ http://storehouse.sakura.ne.jp/rua/
22
+
21
23
  == Example
22
24
 
23
25
  require 'rua'
@@ -26,6 +28,8 @@ http://rubyforge.org/frs/?group_id=4845
26
28
 
27
29
  rua = Rua.new(:all)
28
30
  #rua.openlibs(:base, :package, :string)
31
+ #rua.secure = false
32
+ rua.abort_by_error = false
29
33
  rua.error_handler = lambda do |e, ar|
30
34
  p e
31
35
  p ar.to_hash
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.3.0"
19
+ #define VERSION "0.3.1"
20
20
  #define REF_RBOBJ "self"
21
21
 
22
22
  static const char *insecure_methods[] = {
@@ -94,6 +94,8 @@ void Init_rua() {
94
94
  rb_define_method(Rua, "[]=", rua_set, 2);
95
95
  rb_define_method(Rua, "secure", rua_get_secure, 0);
96
96
  rb_define_method(Rua, "secure=", rua_set_secure, 1);
97
+ rb_define_method(Rua, "abort_by_error", rua_get_abort_by_error, 0);
98
+ rb_define_method(Rua, "abort_by_error=", rua_set_abort_by_error, 1);
97
99
  rb_define_method(Rua, "error_handler", rua_get_error_handler, 0);
98
100
  rb_define_method(Rua, "error_handler=", rua_set_error_handler, 1);
99
101
  rb_define_method(Rua, "method_missing", rua_method_missing, -1);
@@ -138,6 +140,8 @@ static VALUE rua_alloc(VALUE klass) {
138
140
  p->R = ALLOC(struct rua_state);
139
141
  p->R->rua = Qnil;
140
142
  p->R->error_handler = Qnil;
143
+ p->R->secure = 1;
144
+ p->R->abort_by_error = 1;
141
145
  return Data_Wrap_Struct(klass, rua_mark, rua_free, p);
142
146
  }
143
147
 
@@ -169,6 +173,7 @@ static VALUE rua_initialize(int argc, VALUE *argv, VALUE self) {
169
173
  p->R->rua = self;
170
174
  p->R->error_handler = Qnil;
171
175
  p->R->secure = 1;
176
+ p->R->abort_by_error = 1;
172
177
 
173
178
  if (argc > 0) {
174
179
  rua_openlibs(argc, argv, self);
@@ -312,6 +317,34 @@ static VALUE rua_set_secure(VALUE self, VALUE secure) {
312
317
  return Qnil;
313
318
  }
314
319
 
320
+ /**
321
+ * get abort flag.
322
+ */
323
+ static VALUE rua_get_abort_by_error(VALUE self) {
324
+ struct rua *p;
325
+
326
+ Data_Get_Struct(self, struct rua, p);
327
+ return p->R->abort_by_error ? Qtrue : Qfalse;
328
+ }
329
+
330
+ /**
331
+ * set abort flag.
332
+ */
333
+ static VALUE rua_set_abort_by_error(VALUE self, VALUE abort_by_error) {
334
+ struct rua *p;
335
+
336
+ Data_Get_Struct(self, struct rua, p);
337
+
338
+ switch (TYPE(abort_by_error)) {
339
+ case T_TRUE: p->R->abort_by_error = 1; break;
340
+ case T_FALSE: p->R->abort_by_error = 0; break;
341
+ default:
342
+ rb_raise(rb_eTypeError, "wrong argument type %s (expected TrueClass or FalseClass)", rua_classname_ptr(abort_by_error));
343
+ break;
344
+ }
345
+
346
+ return Qnil;
347
+ }
315
348
 
316
349
  /**
317
350
  * get error handler.
@@ -847,7 +880,7 @@ static void rua_newtable_from_obj(lua_State *L, VALUE obj, struct rua_state *R)
847
880
 
848
881
  static int rua_proc_call(lua_State *L) {
849
882
  struct rua_state *R;
850
- VALUE proc, args, last, retval, errargs;
883
+ VALUE proc, args, last, retval, errargs, errmsg;
851
884
  int i, n, status;
852
885
  lua_Debug ar;
853
886
 
@@ -870,11 +903,13 @@ static int rua_proc_call(lua_State *L) {
870
903
  }
871
904
 
872
905
  if (status != 0) {
906
+ errmsg = rb_check_convert_type(ruby_errinfo, T_STRING, "String", "to_s");
907
+
873
908
  if (rua_obj_is_executable(R->error_handler)) {
874
909
  errargs = rb_ary_new();
875
910
  rb_ary_push(errargs, ruby_errinfo);
876
911
 
877
- if (lua_getstack(L, 0, &ar) && lua_getinfo(L, "nSlu", &ar)) {
912
+ if (lua_getstack(L, 1, &ar) && lua_getinfo(L, "nSlu", &ar)) {
878
913
  rb_ary_push(errargs, rua_toruadebug(&ar));
879
914
  }
880
915
 
@@ -887,8 +922,12 @@ static int rua_proc_call(lua_State *L) {
887
922
  } else {
888
923
  retval = Qnil;
889
924
  }
925
+
926
+ if (R->abort_by_error) {
927
+ return luaL_error(L, "%s", StringValuePtr(errmsg));
928
+ }
890
929
  }
891
-
930
+
892
931
  rua_pushrbval(L, retval, R);
893
932
  return 1;
894
933
  }
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.3.0
7
- date: 2007-11-24 00:00:00 +09:00
6
+ version: 0.3.1
7
+ date: 2007-11-25 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