rua 0.4.6-mswin32 → 0.4.7-mswin32

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. data/ext/rua.c +83 -10
  2. data/lib/i386-mswin32/rua.so +0 -0
  3. metadata +2 -2
data/ext/rua.c CHANGED
@@ -8,6 +8,7 @@ __declspec(dllexport) void Init_rua(void);
8
8
  #include <malloc.h>
9
9
  #include <errno.h>
10
10
  #include <stdarg.h>
11
+ #include <math.h>
11
12
 
12
13
  #include "lua.h"
13
14
  #include "lualib.h"
@@ -36,7 +37,7 @@ __declspec(dllexport) void Init_rua(void);
36
37
  #define RARRAY_LEN(s) (RARRAY(s)->len)
37
38
  #endif
38
39
 
39
- #define VERSION "0.4.6"
40
+ #define VERSION "0.4.7"
40
41
  #define REF_RBOBJ "self"
41
42
 
42
43
  #define ICONV_JIS "ISO-2022-JP"
@@ -119,7 +120,7 @@ void Init_rua() {
119
120
  //rb_define_const(Rua, "UTF8", rb_str_new2(ICONV_UTF8));
120
121
  rb_define_private_method(Rua, "initialize", rua_initialize, -1);
121
122
  rb_define_method(Rua, "openlibs", rua_openlibs, -1);
122
- rb_define_method(Rua, "eval", rua_eval, 1);
123
+ rb_define_method(Rua, "eval", rua_eval, -1);
123
124
  rb_define_method(Rua, "[]", rua_get, 1);
124
125
  rb_define_method(Rua, "[]=", rua_set, 2);
125
126
  rb_define_method(Rua, "secure", rua_get_secure, 0);
@@ -133,6 +134,8 @@ void Init_rua() {
133
134
  rb_define_method(Rua, "error_handler", rua_get_error_handler, 0);
134
135
  rb_define_method(Rua, "error_handler=", rua_set_error_handler, 1);
135
136
  rb_define_method(Rua, "method_missing", rua_method_missing, -1);
137
+ rb_define_method(Rua, "accept_block", rua_get_accept_block, 0);
138
+ rb_define_method(Rua, "accept_block=", rua_set_accept_block, 1);
136
139
 
137
140
  m_method_unbound = rb_funcall(rb_cObject, rb_intern("instance_method"), 1, ID2SYM(rb_intern("method")));
138
141
  m_methods_unbound = rb_funcall(rb_cObject, rb_intern("instance_method"), 1, ID2SYM(rb_intern("methods")));
@@ -225,6 +228,7 @@ static VALUE rua_initialize(int argc, VALUE *argv, VALUE self) {
225
228
  p->R->secure = 1;
226
229
  p->R->abort_by_error = 1;
227
230
  p->R->wrap_error = 1;
231
+ p->R->accept_block = 1;
228
232
 
229
233
  if (argc > 0) {
230
234
  rua_openlibs(argc, argv, self);
@@ -289,13 +293,20 @@ static VALUE rua_openlibs(int argc, VALUE *argv, VALUE self) {
289
293
  /**
290
294
  * evaluates string.
291
295
  */
292
- static VALUE rua_eval(VALUE self, VALUE str) {
296
+ static VALUE rua_eval(int argc, VALUE *argv, VALUE self) {
293
297
  struct rua *p;
294
- VALUE errinfo;
298
+ VALUE str, script_name, errinfo;
295
299
  const char *errmsg = NULL;
296
- int pretop, result = -1;
300
+ int pretop, loaded = -1, result = -1;
301
+
302
+ rb_scan_args(argc, argv, "11", &str, &script_name);
297
303
 
298
304
  Check_Type(str, T_STRING);
305
+
306
+ if (!NIL_P(script_name)) {
307
+ Check_Type(script_name, T_STRING);
308
+ }
309
+
299
310
  Data_Get_Struct(self, struct rua, p);
300
311
 
301
312
  if (!NIL_P(p->R->external_charset)) {
@@ -304,7 +315,13 @@ static VALUE rua_eval(VALUE self, VALUE str) {
304
315
 
305
316
  pretop = lua_gettop(p->L);
306
317
 
307
- if (luaL_loadstring(p->L, RSTRING_PTR(str)) != 0) {
318
+ if (NIL_P(script_name)) {
319
+ loaded = luaL_loadstring(p->L, RSTRING_PTR(str));
320
+ } else {
321
+ loaded = luaL_loadbuffer(p->L, RSTRING_PTR(str), RSTRING_LEN(str), RSTRING_PTR(script_name));
322
+ }
323
+
324
+ if (loaded != 0) {
308
325
  int curtop = lua_gettop(p->L);
309
326
 
310
327
  if (!lua_isnil(p->L, -1)) {
@@ -540,11 +557,40 @@ static VALUE rua_method_missing(int argc, VALUE *argv, VALUE self) {
540
557
  }
541
558
  }
542
559
 
560
+ /**
561
+ * get accept block flag.
562
+ */
563
+ static VALUE rua_get_accept_block(VALUE self) {
564
+ struct rua *p;
565
+
566
+ Data_Get_Struct(self, struct rua, p);
567
+ return p->R->accept_block ? Qtrue : Qfalse;
568
+ }
569
+
570
+ /**
571
+ * set accept block flag.
572
+ */
573
+ static VALUE rua_set_accept_block(VALUE self, VALUE accept_block) {
574
+ struct rua *p;
575
+
576
+ Data_Get_Struct(self, struct rua, p);
577
+
578
+ switch (TYPE(accept_block)) {
579
+ case T_TRUE: p->R->accept_block = 1; break;
580
+ case T_FALSE: p->R->accept_block = 0; break;
581
+ default:
582
+ rb_raise(rb_eTypeError, "wrong argument type %s (expected TrueClass or FalseClass)", rua_classname_ptr(accept_block));
583
+ break;
584
+ }
585
+
586
+ return Qnil;
587
+ }
588
+
543
589
  // ------------------------------------------------------------------
544
590
 
545
591
  static VALUE rua_ref_alloc(VALUE klass) {
546
592
  struct rua_ref *p = ALLOC(struct rua_ref);
547
-
593
+ p->is_ruby = 0;
548
594
  return Data_Wrap_Struct(klass, rua_ref_mark, rua_ref_free, p);
549
595
  }
550
596
 
@@ -565,6 +611,18 @@ static void rua_ref_free(struct rua_ref *p) {
565
611
  xfree(p);
566
612
  }
567
613
 
614
+ static void rua_ref_set_ruby_flag(VALUE self, int is_ruby) {
615
+ struct rua_ref *p;
616
+ Data_Get_Struct(self, struct rua_ref, p);
617
+ p->is_ruby = is_ruby;
618
+ }
619
+
620
+ static int rua_ref_get_ruby_flag(VALUE self) {
621
+ struct rua_ref *p;
622
+ Data_Get_Struct(self, struct rua_ref, p);
623
+ return p->is_ruby;
624
+ }
625
+
568
626
  // ------------------------------------------------------------------
569
627
 
570
628
  /**
@@ -891,7 +949,7 @@ static VALUE rua_torbval(lua_State *L, int idx, struct rua_state *R) {
891
949
 
892
950
  switch (lua_type(L, idx)) {
893
951
  case LUA_TNUMBER:
894
- rbval = rb_float_new(lua_tonumber(L, idx));
952
+ rbval = rua_torbnum(L, idx);
895
953
  break;
896
954
 
897
955
  case LUA_TBOOLEAN:
@@ -917,7 +975,11 @@ static VALUE rua_torbval(lua_State *L, int idx, struct rua_state *R) {
917
975
  break;
918
976
 
919
977
  case LUA_TFUNCTION:
920
- rbval = rua_toruaobj(RuaFunc, L, idx, R);
978
+ {
979
+ int type_is_cfunction = lua_iscfunction(L, idx);
980
+ rbval = rua_toruaobj(RuaFunc, L, idx, R);
981
+ rua_ref_set_ruby_flag(rbval, type_is_cfunction);
982
+ }
921
983
  break;
922
984
 
923
985
  case LUA_TTHREAD:
@@ -1190,7 +1252,7 @@ static int rua_proc_call(lua_State *L) {
1190
1252
  last = rb_ary_entry(args, -1);
1191
1253
  rb_ary_push(args, proc);
1192
1254
 
1193
- if (rb_obj_is_kind_of(last, RuaFunc)) {
1255
+ if (R->accept_block && rb_obj_is_kind_of(last, RuaFunc) && !rua_ref_get_ruby_flag(last)) {
1194
1256
  retval = rb_protect(_rua_proc_call_with_block, args, &status);
1195
1257
  } else {
1196
1258
  retval = rb_protect(_rua_proc_call, args, &status);
@@ -1433,3 +1495,14 @@ static VALUE rua_iconv(const char *to, const char *from, VALUE in) {
1433
1495
 
1434
1496
  return out;
1435
1497
  }
1498
+
1499
+ static VALUE rua_torbnum(lua_State *L, int idx) {
1500
+ double luanum = lua_tonumber(L, idx);
1501
+ double truncated = floor(luanum);
1502
+
1503
+ if (luanum == truncated) {
1504
+ return INT2NUM(lua_tointeger(L, idx));
1505
+ } else {
1506
+ return rb_float_new(luanum);
1507
+ }
1508
+ }
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rua
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.6
4
+ version: 0.4.7
5
5
  platform: mswin32
6
6
  authors:
7
7
  - winebarrel
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-09-21 00:00:00 +09:00
12
+ date: 2008-09-30 00:00:00 +09:00
13
13
  default_executable:
14
14
  dependencies: []
15
15