rua 0.2.1-mswin32 → 0.2.2-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.
- data/README.txt +8 -7
- data/ext/rua.c +60 -32
- data/lib/i386-mswin32/rua.so +0 -0
- metadata +4 -6
- data/ext/rua.h +0 -61
data/README.txt
CHANGED
@@ -10,6 +10,10 @@ Rua is a library for using Lua under Ruby.
|
|
10
10
|
|
11
11
|
http://rubyforge.org/projects/rua
|
12
12
|
|
13
|
+
== Install
|
14
|
+
|
15
|
+
gem install rua
|
16
|
+
|
13
17
|
== Download
|
14
18
|
|
15
19
|
http://rubyforge.org/frs/?group_id=4845
|
@@ -19,15 +23,12 @@ http://rubyforge.org/frs/?group_id=4845
|
|
19
23
|
require 'rua'
|
20
24
|
|
21
25
|
class MyClass; end
|
22
|
-
|
23
|
-
error_handler = lambda do |e|
|
24
|
-
p e
|
25
|
-
end
|
26
26
|
|
27
|
-
rua = Rua.new(
|
28
|
-
rua.openlibs(:all)
|
27
|
+
rua = Rua.new(:all)
|
29
28
|
#rua.openlibs(:base, :package, :string)
|
30
|
-
|
29
|
+
rua.error_handler = lambda do |e|
|
30
|
+
p e
|
31
|
+
end
|
31
32
|
|
32
33
|
rua.str = 'xxx'
|
33
34
|
rua.num = 100
|
data/ext/rua.c
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
/* */
|
1
2
|
#ifdef _WIN32
|
2
3
|
#pragma warning(disable:4311)
|
3
4
|
#pragma warning(disable:4312)
|
@@ -15,7 +16,7 @@ __declspec(dllexport) void Init_rua(void);
|
|
15
16
|
|
16
17
|
#include "rua.h"
|
17
18
|
|
18
|
-
#define VERSION "0.2.
|
19
|
+
#define VERSION "0.2.2"
|
19
20
|
#define REF_RBOBJ "self"
|
20
21
|
|
21
22
|
static const char *insecure_methods[] = {
|
@@ -92,6 +93,8 @@ void Init_rua() {
|
|
92
93
|
rb_define_method(Rua, "[]=", rua_set, 2);
|
93
94
|
rb_define_method(Rua, "secure", rua_get_secure, 0);
|
94
95
|
rb_define_method(Rua, "secure=", rua_set_secure, 1);
|
96
|
+
rb_define_method(Rua, "error_handler", rua_get_error_handler, 0);
|
97
|
+
rb_define_method(Rua, "error_handler=", rua_set_error_handler, 1);
|
95
98
|
rb_define_method(Rua, "method_missing", rua_method_missing, -1);
|
96
99
|
|
97
100
|
rb_define_alloc_func(RuaFunc, rua_func_alloc);
|
@@ -118,6 +121,7 @@ void Init_rua() {
|
|
118
121
|
|
119
122
|
static VALUE rua_alloc(VALUE klass) {
|
120
123
|
struct rua *p = ALLOC(struct rua);
|
124
|
+
p->R = ALLOC(struct rua_state);
|
121
125
|
|
122
126
|
return Data_Wrap_Struct(klass, 0, rua_free, p);
|
123
127
|
}
|
@@ -127,6 +131,10 @@ static void rua_free(struct rua *p) {
|
|
127
131
|
lua_close(p->L);
|
128
132
|
}
|
129
133
|
|
134
|
+
if (p->R) {
|
135
|
+
free(p->R);
|
136
|
+
}
|
137
|
+
|
130
138
|
free(p);
|
131
139
|
}
|
132
140
|
|
@@ -135,20 +143,16 @@ static void rua_free(struct rua *p) {
|
|
135
143
|
*/
|
136
144
|
static VALUE rua_initialize(int argc, VALUE *argv, VALUE self) {
|
137
145
|
struct rua *p;
|
138
|
-
VALUE error_handler;
|
139
146
|
|
140
147
|
Data_Get_Struct(self, struct rua, p);
|
141
|
-
p->L =
|
148
|
+
p->L = lua_open();
|
149
|
+
p->R->secure = 1;
|
150
|
+
p->R->error_handler = Qnil;
|
142
151
|
|
143
|
-
if (
|
144
|
-
|
145
|
-
} else if (!rua_obj_is_executable(error_handler)) {
|
146
|
-
rb_raise(rb_eTypeError, "wrong argument type %s (expected Proc or Method)", rua_classname_ptr(error_handler));
|
152
|
+
if (argc > 0) {
|
153
|
+
rua_openlibs(argc, argv, self);
|
147
154
|
}
|
148
155
|
|
149
|
-
p->L = lua_open();
|
150
|
-
p->R.secure = 1;
|
151
|
-
p->R.error_handler = error_handler;
|
152
156
|
return Qnil;
|
153
157
|
}
|
154
158
|
|
@@ -249,7 +253,7 @@ static VALUE rua_set(VALUE self, VALUE key, VALUE val) {
|
|
249
253
|
|
250
254
|
Data_Get_Struct(self, struct rua, p);
|
251
255
|
|
252
|
-
if (p->R
|
256
|
+
if (p->R->secure && (rb_equal(rb_cModule, val) || rb_equal(rb_cClass, val))) {
|
253
257
|
rb_raise(RuaError, "set insecure value %s", rua_to_sptr(val));
|
254
258
|
}
|
255
259
|
|
@@ -265,7 +269,7 @@ static VALUE rua_get_secure(VALUE self) {
|
|
265
269
|
struct rua *p;
|
266
270
|
|
267
271
|
Data_Get_Struct(self, struct rua, p);
|
268
|
-
return p->R
|
272
|
+
return p->R->secure ? Qtrue : Qfalse;
|
269
273
|
}
|
270
274
|
|
271
275
|
/*
|
@@ -277,8 +281,8 @@ static VALUE rua_set_secure(VALUE self, VALUE secure) {
|
|
277
281
|
Data_Get_Struct(self, struct rua, p);
|
278
282
|
|
279
283
|
switch (TYPE(secure)) {
|
280
|
-
case T_TRUE: p->R
|
281
|
-
case T_FALSE: p->R
|
284
|
+
case T_TRUE: p->R->secure = 1; break;
|
285
|
+
case T_FALSE: p->R->secure = 0; break;
|
282
286
|
default:
|
283
287
|
rb_raise(rb_eTypeError, "wrong argument type %s (expected TrueClass or FalseClass)", rua_classname_ptr(secure));
|
284
288
|
break;
|
@@ -287,6 +291,32 @@ static VALUE rua_set_secure(VALUE self, VALUE secure) {
|
|
287
291
|
return Qnil;
|
288
292
|
}
|
289
293
|
|
294
|
+
|
295
|
+
/*
|
296
|
+
* get error handler flag.
|
297
|
+
*/
|
298
|
+
static VALUE rua_get_error_handler(VALUE self) {
|
299
|
+
struct rua *p;
|
300
|
+
|
301
|
+
Data_Get_Struct(self, struct rua, p);
|
302
|
+
return p->R->error_handler;
|
303
|
+
}
|
304
|
+
|
305
|
+
/*
|
306
|
+
* set error handler flag.
|
307
|
+
*/
|
308
|
+
static VALUE rua_set_error_handler(VALUE self, VALUE error_handler) {
|
309
|
+
struct rua *p;
|
310
|
+
|
311
|
+
if (!NIL_P(error_handler) && !rua_obj_is_executable(error_handler)) {
|
312
|
+
rb_raise(rb_eTypeError, "wrong argument type %s (expected Proc or Method)", rua_classname_ptr(error_handler));
|
313
|
+
}
|
314
|
+
|
315
|
+
Data_Get_Struct(self, struct rua, p);
|
316
|
+
p->R->error_handler = error_handler;
|
317
|
+
return Qnil;
|
318
|
+
}
|
319
|
+
|
290
320
|
/*
|
291
321
|
* dispatch Rua#[], Rua#[]=.
|
292
322
|
*/
|
@@ -412,7 +442,7 @@ static VALUE rua_thread_resume(int argc, VALUE *argv, VALUE self) {
|
|
412
442
|
|
413
443
|
// ------------------------------------------------------------------
|
414
444
|
|
415
|
-
static VALUE rua_tomultiretval(lua_State *L, int pretop, struct rua_state R) {
|
445
|
+
static VALUE rua_tomultiretval(lua_State *L, int pretop, struct rua_state *R) {
|
416
446
|
VALUE retval;
|
417
447
|
int nresults, i;
|
418
448
|
|
@@ -436,7 +466,7 @@ static VALUE rua_tomultiretval(lua_State *L, int pretop, struct rua_state R) {
|
|
436
466
|
}
|
437
467
|
}
|
438
468
|
|
439
|
-
static VALUE rua_torbval(lua_State *L, int idx, struct rua_state R) {
|
469
|
+
static VALUE rua_torbval(lua_State *L, int idx, struct rua_state *R) {
|
440
470
|
VALUE rbval = Qnil;
|
441
471
|
|
442
472
|
switch (lua_type(L, idx)) {
|
@@ -502,7 +532,7 @@ static VALUE rua_torbobj(lua_State *L, int idx) {
|
|
502
532
|
return rbobj;
|
503
533
|
}
|
504
534
|
|
505
|
-
static VALUE rua_tohash(lua_State *L, int idx, struct rua_state R) {
|
535
|
+
static VALUE rua_tohash(lua_State *L, int idx, struct rua_state *R) {
|
506
536
|
VALUE hash, key, val;
|
507
537
|
int tblidx;
|
508
538
|
|
@@ -522,7 +552,7 @@ static VALUE rua_tohash(lua_State *L, int idx, struct rua_state R) {
|
|
522
552
|
return hash;
|
523
553
|
}
|
524
554
|
|
525
|
-
static void rua_pushrbval(lua_State *L, VALUE rbval, struct rua_state R) {
|
555
|
+
static void rua_pushrbval(lua_State *L, VALUE rbval, struct rua_state *R) {
|
526
556
|
struct rua_ref *p;
|
527
557
|
|
528
558
|
switch (TYPE(rbval)) {
|
@@ -557,7 +587,7 @@ static void rua_pushrbval(lua_State *L, VALUE rbval, struct rua_state R) {
|
|
557
587
|
break;
|
558
588
|
|
559
589
|
default:
|
560
|
-
if (R
|
590
|
+
if (R->secure && (rb_equal(rb_cModule, rbval) || rb_equal(rb_cClass, rbval))) {
|
561
591
|
fprintf(stderr, "warning: convert insecure value %s", rua_to_sptr(rbval));
|
562
592
|
lua_pushnil(L);
|
563
593
|
} else if (rb_obj_is_kind_of(rbval, RuaFunc)) {
|
@@ -568,9 +598,8 @@ static void rua_pushrbval(lua_State *L, VALUE rbval, struct rua_state R) {
|
|
568
598
|
lua_rawgeti(L, LUA_REGISTRYINDEX, p->ref);
|
569
599
|
} else if (rua_obj_is_executable(rbval)) {
|
570
600
|
lua_pushlightuserdata(L, (void *) rbval);
|
571
|
-
lua_pushlightuserdata(L,
|
572
|
-
|
573
|
-
lua_pushcclosure(L, rua_proc_call, 3);
|
601
|
+
lua_pushlightuserdata(L, R);
|
602
|
+
lua_pushcclosure(L, rua_proc_call, 2);
|
574
603
|
} else {
|
575
604
|
rua_newtable_from_obj(L, rbval, R);
|
576
605
|
}
|
@@ -579,7 +608,7 @@ static void rua_pushrbval(lua_State *L, VALUE rbval, struct rua_state R) {
|
|
579
608
|
}
|
580
609
|
}
|
581
610
|
|
582
|
-
static void rua_newtable_from_ary(lua_State *L, VALUE ary, struct rua_state R) {
|
611
|
+
static void rua_newtable_from_ary(lua_State *L, VALUE ary, struct rua_state *R) {
|
583
612
|
VALUE entry;
|
584
613
|
int i, tblidx;
|
585
614
|
|
@@ -594,7 +623,7 @@ static void rua_newtable_from_ary(lua_State *L, VALUE ary, struct rua_state R) {
|
|
594
623
|
}
|
595
624
|
}
|
596
625
|
|
597
|
-
static void rua_newtable_from_hash(lua_State *L, VALUE hash, struct rua_state R) {
|
626
|
+
static void rua_newtable_from_hash(lua_State *L, VALUE hash, struct rua_state *R) {
|
598
627
|
VALUE keys, key, val;
|
599
628
|
int i, tblidx;
|
600
629
|
|
@@ -611,7 +640,7 @@ static void rua_newtable_from_hash(lua_State *L, VALUE hash, struct rua_state R)
|
|
611
640
|
}
|
612
641
|
}
|
613
642
|
|
614
|
-
static void rua_newtable_from_obj(lua_State *L, VALUE obj, struct rua_state R) {
|
643
|
+
static void rua_newtable_from_obj(lua_State *L, VALUE obj, struct rua_state *R) {
|
615
644
|
VALUE methods, name, method;
|
616
645
|
int i, tblidx;
|
617
646
|
|
@@ -627,7 +656,7 @@ static void rua_newtable_from_obj(lua_State *L, VALUE obj, struct rua_state R) {
|
|
627
656
|
name = rb_ary_entry(methods, i);
|
628
657
|
method = rb_funcall(obj, rb_intern("method"), 1, name);
|
629
658
|
|
630
|
-
if (R
|
659
|
+
if (R->secure && rua_name_is_insecure_method(StringValuePtr(name))) {
|
631
660
|
continue;
|
632
661
|
}
|
633
662
|
|
@@ -638,13 +667,12 @@ static void rua_newtable_from_obj(lua_State *L, VALUE obj, struct rua_state R) {
|
|
638
667
|
}
|
639
668
|
|
640
669
|
static int rua_proc_call(lua_State *L) {
|
641
|
-
struct rua_state R;
|
670
|
+
struct rua_state *R;
|
642
671
|
VALUE proc, args, retval, errargs;
|
643
672
|
int i, n, status;
|
644
673
|
|
645
674
|
proc = (VALUE) lua_touserdata(L, lua_upvalueindex(1));
|
646
|
-
R
|
647
|
-
R.secure = (int) lua_touserdata(L, lua_upvalueindex(3));
|
675
|
+
R = (struct rua_state *) lua_touserdata(L, lua_upvalueindex(2));
|
648
676
|
args = rb_ary_new();
|
649
677
|
n = lua_gettop(L);
|
650
678
|
|
@@ -656,10 +684,10 @@ static int rua_proc_call(lua_State *L) {
|
|
656
684
|
retval = rb_protect(_rua_proc_call, args, &status);
|
657
685
|
|
658
686
|
if (status != 0) {
|
659
|
-
if (rua_obj_is_executable(R
|
687
|
+
if (rua_obj_is_executable(R->error_handler)) {
|
660
688
|
errargs = rb_ary_new();
|
661
689
|
rb_ary_push(errargs, ruby_errinfo);
|
662
|
-
rb_ary_push(errargs, R
|
690
|
+
rb_ary_push(errargs, R->error_handler);
|
663
691
|
retval = rb_protect(_rua_proc_call, errargs, &status);
|
664
692
|
|
665
693
|
if (status != 0) {
|
@@ -680,7 +708,7 @@ static VALUE _rua_proc_call(VALUE args) {
|
|
680
708
|
return rb_apply(proc, rb_intern("call"), args);
|
681
709
|
}
|
682
710
|
|
683
|
-
static VALUE rua_toruaobj(VALUE klass, lua_State *L, int idx, struct rua_state R) {
|
711
|
+
static VALUE rua_toruaobj(VALUE klass, lua_State *L, int idx, struct rua_state *R) {
|
684
712
|
struct rua_ref *p;
|
685
713
|
VALUE ruaobj;
|
686
714
|
|
data/lib/i386-mswin32/rua.so
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
|
-
rubygems_version: 0.9.
|
2
|
+
rubygems_version: 0.9.4
|
3
3
|
specification_version: 1
|
4
4
|
name: rua
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.2.
|
7
|
-
date: 2007-11-
|
6
|
+
version: 0.2.2
|
7
|
+
date: 2007-11-19 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
|
@@ -32,16 +32,14 @@ files:
|
|
32
32
|
- README.txt
|
33
33
|
- lib/i386-mswin32/rua.so
|
34
34
|
- ext/rua.c
|
35
|
-
- ext/rua.h
|
36
35
|
test_files: []
|
37
36
|
|
38
37
|
rdoc_options:
|
39
38
|
- --title
|
40
|
-
- Rua -
|
39
|
+
- Rua - library for using Lua under Ruby.
|
41
40
|
extra_rdoc_files:
|
42
41
|
- README.txt
|
43
42
|
- ext/rua.c
|
44
|
-
- ext/rua.h
|
45
43
|
executables: []
|
46
44
|
|
47
45
|
extensions: []
|
data/ext/rua.h
DELETED
@@ -1,61 +0,0 @@
|
|
1
|
-
#ifndef __RUA_H__
|
2
|
-
#define __RUA_H__
|
3
|
-
|
4
|
-
struct rua_state {
|
5
|
-
VALUE error_handler;
|
6
|
-
int secure;
|
7
|
-
};
|
8
|
-
|
9
|
-
struct rua {
|
10
|
-
lua_State *L;
|
11
|
-
struct rua_state R;
|
12
|
-
};
|
13
|
-
|
14
|
-
struct rua_ref {
|
15
|
-
lua_State *L;
|
16
|
-
struct rua_state R;
|
17
|
-
int ref;
|
18
|
-
};
|
19
|
-
|
20
|
-
void Init_rua();
|
21
|
-
static VALUE rua_alloc(VALUE klass);
|
22
|
-
static void rua_free(struct rua *p);
|
23
|
-
static VALUE rua_initialize(int argc, VALUE *argv, VALUE self);
|
24
|
-
static VALUE rua_openlibs(int argc, VALUE *argv, VALUE self);
|
25
|
-
static VALUE rua_eval(VALUE self, VALUE str);
|
26
|
-
static VALUE rua_get(VALUE self, VALUE key);
|
27
|
-
static VALUE rua_set(VALUE self, VALUE key, VALUE val);
|
28
|
-
static VALUE rua_get_secure(VALUE self);
|
29
|
-
static VALUE rua_set_secure(VALUE self, VALUE secure);
|
30
|
-
static VALUE rua_method_missing(int argc, VALUE *argv, VALUE self);
|
31
|
-
|
32
|
-
static VALUE rua_func_alloc(VALUE klass);
|
33
|
-
static VALUE rua_func_initialize(VALUE self);
|
34
|
-
static VALUE rua_func_call(int argc, VALUE *argv, VALUE self);
|
35
|
-
//static VALUE rua_func_get(VALUE self, VALUE key);
|
36
|
-
//static VALUE rua_func_set(VALUE self, VALUE key, VALUE val);
|
37
|
-
|
38
|
-
static VALUE rua_thread_alloc(VALUE klass);
|
39
|
-
static VALUE rua_thread_initialize(VALUE self);
|
40
|
-
static VALUE rua_thread_resume(int argc, VALUE *argv, VALUE self);
|
41
|
-
|
42
|
-
static VALUE rua_tomultiretval(lua_State *L, int pretop, struct rua_state R);
|
43
|
-
static VALUE rua_torbval(lua_State *L, int idx, struct rua_state R);
|
44
|
-
static int rua_is_rbobj(lua_State *L, int idx);
|
45
|
-
static VALUE rua_torbobj(lua_State *L, int idx);
|
46
|
-
static VALUE rua_tohash(lua_State *L, int idx, struct rua_state R);
|
47
|
-
static void rua_pushrbval(lua_State *L, VALUE rbval, struct rua_state R);
|
48
|
-
static void rua_newtable_from_ary(lua_State *L, VALUE ary, struct rua_state R);
|
49
|
-
static void rua_newtable_from_hash(lua_State *L, VALUE hash, struct rua_state R);
|
50
|
-
static void rua_newtable_from_obj(lua_State *L, VALUE obj, struct rua_state R);
|
51
|
-
static int rua_proc_call(lua_State *L);
|
52
|
-
static VALUE _rua_proc_call(VALUE args);
|
53
|
-
static VALUE rua_toruaobj(VALUE klass, lua_State *L, int idx, struct rua_state R);
|
54
|
-
static VALUE rua_obj_is_executable(VALUE obj);
|
55
|
-
static int rua_name_is_insecure_method(const char *name);
|
56
|
-
static VALUE rua_to_s(VALUE v);
|
57
|
-
static const char *rua_to_sptr(VALUE v);
|
58
|
-
static VALUE rua_classname(VALUE v);
|
59
|
-
static const char *rua_classname_ptr(VALUE v);
|
60
|
-
|
61
|
-
#endif
|