rua 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- data/README.txt +6 -0
- data/ext/rua.c +40 -3
- data/ext/rua.h +2 -0
- metadata +2 -2
data/README.txt
CHANGED
@@ -10,6 +10,8 @@ Rua is a library for using Lua under Ruby.
|
|
10
10
|
|
11
11
|
require 'rua'
|
12
12
|
|
13
|
+
class MyClass; end
|
14
|
+
|
13
15
|
error_handler = lambda do |e|
|
14
16
|
p e
|
15
17
|
end
|
@@ -28,6 +30,8 @@ Rua is a library for using Lua under Ruby.
|
|
28
30
|
raise 'err called.'
|
29
31
|
end
|
30
32
|
rua.Time = Time
|
33
|
+
rua.MyClass = MyClass
|
34
|
+
|
31
35
|
puts rua.eval(<<-EOS)
|
32
36
|
print('hello Rua!')
|
33
37
|
print(str)
|
@@ -35,6 +39,7 @@ Rua is a library for using Lua under Ruby.
|
|
35
39
|
proc()
|
36
40
|
err()
|
37
41
|
print(Time.new().to_s())
|
42
|
+
my_obj = MyClass.new()
|
38
43
|
|
39
44
|
f = function()
|
40
45
|
print('f() called.')
|
@@ -44,6 +49,7 @@ Rua is a library for using Lua under Ruby.
|
|
44
49
|
EOS
|
45
50
|
|
46
51
|
rua.f.call
|
52
|
+
p rua.my_obj
|
47
53
|
p rua.eval('return 1, 2, 3')
|
48
54
|
|
49
55
|
co = rua.eval(<<-EOS)
|
data/ext/rua.c
CHANGED
@@ -15,6 +15,9 @@ __declspec(dllexport) void Init_rua(void);
|
|
15
15
|
|
16
16
|
#include "rua.h"
|
17
17
|
|
18
|
+
#define REF_RBOBJ "__self"
|
19
|
+
#define VERSION "0.1.5"
|
20
|
+
|
18
21
|
static const char *insecure_methods[] = {
|
19
22
|
"__id__",
|
20
23
|
"__send__",
|
@@ -81,7 +84,7 @@ void Init_rua() {
|
|
81
84
|
RuaError = rb_define_class("RuaError", rb_eStandardError);
|
82
85
|
|
83
86
|
rb_define_alloc_func(Rua, rua_alloc);
|
84
|
-
rb_define_const(Rua, "VERSION", rb_str_new2(
|
87
|
+
rb_define_const(Rua, "VERSION", rb_str_new2(VERSION));
|
85
88
|
rb_define_private_method(Rua, "initialize", rua_initialize, -1);
|
86
89
|
rb_define_method(Rua, "openlibs", rua_openlibs, -1);
|
87
90
|
rb_define_method(Rua, "eval", rua_eval, 1);
|
@@ -375,7 +378,7 @@ static VALUE rua_thread_resume(int argc, VALUE *argv, VALUE self) {
|
|
375
378
|
lua_getglobal(p->L, "coroutine");
|
376
379
|
pretop = lua_gettop(p->L);
|
377
380
|
lua_pushstring(p->L, "resume");
|
378
|
-
|
381
|
+
lua_rawget(p->L, pretop);
|
379
382
|
lua_rawgeti(p->L, LUA_REGISTRYINDEX, p->ref);
|
380
383
|
|
381
384
|
for (i = 0; i < argc; i ++) {
|
@@ -428,7 +431,12 @@ static VALUE rua_torbval(lua_State *L, int idx, VALUE error_handler, int secure)
|
|
428
431
|
break;
|
429
432
|
|
430
433
|
case LUA_TTABLE:
|
431
|
-
|
434
|
+
if (rua_is_rbobj(L, idx)) {
|
435
|
+
rbval = rua_torbobj(L, idx);
|
436
|
+
} else {
|
437
|
+
rbval = rua_tohash(L, idx, error_handler, secure);
|
438
|
+
}
|
439
|
+
|
432
440
|
break;
|
433
441
|
|
434
442
|
case LUA_TFUNCTION:
|
@@ -447,6 +455,31 @@ static VALUE rua_torbval(lua_State *L, int idx, VALUE error_handler, int secure)
|
|
447
455
|
return rbval;
|
448
456
|
}
|
449
457
|
|
458
|
+
static int rua_is_rbobj(lua_State *L, int idx) {
|
459
|
+
int tblidx, is_rbobj;
|
460
|
+
|
461
|
+
lua_pushvalue(L, idx);
|
462
|
+
tblidx = lua_gettop(L);
|
463
|
+
lua_pushstring(L, REF_RBOBJ);
|
464
|
+
lua_rawget(L, tblidx);
|
465
|
+
is_rbobj = lua_islightuserdata(L, -1);
|
466
|
+
lua_pop(L, 2);
|
467
|
+
return is_rbobj;
|
468
|
+
}
|
469
|
+
|
470
|
+
static VALUE rua_torbobj(lua_State *L, int idx) {
|
471
|
+
VALUE rbobj;
|
472
|
+
int tblidx;
|
473
|
+
|
474
|
+
lua_pushvalue(L, idx);
|
475
|
+
tblidx = lua_gettop(L);
|
476
|
+
lua_pushstring(L, REF_RBOBJ);
|
477
|
+
lua_rawget(L, tblidx);
|
478
|
+
rbobj = (VALUE) lua_topointer(L, -1);
|
479
|
+
lua_pop(L, 2);
|
480
|
+
return rbobj;
|
481
|
+
}
|
482
|
+
|
450
483
|
static VALUE rua_tohash(lua_State *L, int idx, VALUE error_handler, int secure) {
|
451
484
|
VALUE hash, key, val;
|
452
485
|
int tblidx;
|
@@ -565,6 +598,10 @@ static void rua_newtable_from_obj(lua_State *L, VALUE obj, VALUE error_handler,
|
|
565
598
|
tblidx = lua_gettop(L);
|
566
599
|
methods = rb_check_convert_type(obj, T_ARRAY, "Array", "methods");
|
567
600
|
|
601
|
+
lua_pushstring(L, REF_RBOBJ);
|
602
|
+
lua_pushlightuserdata(L, (void *) obj);
|
603
|
+
lua_settable(L, tblidx);
|
604
|
+
|
568
605
|
for (i = 0; i < RARRAY(methods)->len; i++) {
|
569
606
|
name = rb_ary_entry(methods, i);
|
570
607
|
method = rb_funcall(obj, rb_intern("method"), 1, name);
|
data/ext/rua.h
CHANGED
@@ -42,6 +42,8 @@ static VALUE rua_thread_initialize(VALUE self);
|
|
42
42
|
static VALUE rua_thread_resume(int argc, VALUE *argv, VALUE self);
|
43
43
|
|
44
44
|
static VALUE rua_torbval(lua_State *L, int idx, VALUE error_handler, int secure);
|
45
|
+
static int rua_is_rbobj(lua_State *L, int idx);
|
46
|
+
static VALUE rua_torbobj(lua_State *L, int idx);
|
45
47
|
static VALUE rua_tohash(lua_State *L, int idx, VALUE error_handler, int secure);
|
46
48
|
static void rua_pushrbval(lua_State *L, VALUE rbval, VALUE error_handler, int secure);
|
47
49
|
static void rua_newtable_from_ary(lua_State *L, VALUE ary, VALUE error_handler, int secure);
|
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.1.
|
7
|
-
date: 2007-11-
|
6
|
+
version: 0.1.5
|
7
|
+
date: 2007-11-17 00:00:00 +09:00
|
8
8
|
summary: rua is a library for using Lua under Ruby.
|
9
9
|
require_paths:
|
10
10
|
- lib
|