rua 0.3.5 → 0.3.7

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 (4) hide show
  1. data/README.txt +6 -1
  2. data/ext/rua.c +79 -12
  3. data/ext/rua.h +4 -1
  4. metadata +42 -35
data/README.txt CHANGED
@@ -24,7 +24,10 @@ http://storehouse.sakura.ne.jp/rua/
24
24
 
25
25
  require 'rua'
26
26
 
27
- class MyClass; end
27
+ class MyClass
28
+ def val=(v); @val = v; end
29
+ def val; @val; end
30
+ end
28
31
 
29
32
  rua = Rua.new(:all)
30
33
  #rua.external_charset = Rua::SJIS
@@ -60,6 +63,8 @@ http://storehouse.sakura.ne.jp/rua/
60
63
  err()
61
64
  print(Time.new().to_s())
62
65
  my_obj = MyClass.new()
66
+ my_obj.val = 'my_obj.val'
67
+ print(my_obj.val())
63
68
 
64
69
  f = function()
65
70
  print('f() called.')
data/ext/rua.c CHANGED
@@ -9,6 +9,7 @@ __declspec(dllexport) void Init_rua(void);
9
9
  #include <string.h>
10
10
  #include <malloc.h>
11
11
  #include <errno.h>
12
+ #include <stdarg.h>
12
13
 
13
14
  #include "ruby.h"
14
15
 
@@ -20,7 +21,7 @@ __declspec(dllexport) void Init_rua(void);
20
21
 
21
22
  #include "rua.h"
22
23
 
23
- #define VERSION "0.3.5"
24
+ #define VERSION "0.3.7"
24
25
  #define REF_RBOBJ "self"
25
26
 
26
27
  #define ICONV_JIS "ISO-2022-JP"
@@ -978,7 +979,7 @@ static void rua_pushrbval(lua_State *L, VALUE rbval, struct rua_state *R) {
978
979
  lua_pushlightuserdata(L, (void *) rbval);
979
980
  lua_pushlightuserdata(L, R);
980
981
  lua_pushcclosure(L, rua_proc_call, 2);
981
- rua_set_finalizer(L, -1, rbval, R);
982
+ rua_setmeta2(L, -1, "__gc", rua_finalize_rbobj, 2, rbval, R);
982
983
  } else {
983
984
  rua_newtable_from_obj(L, rbval, R);
984
985
  }
@@ -1021,15 +1022,17 @@ static void rua_newtable_from_hash(lua_State *L, VALUE hash, struct rua_state *R
1021
1022
 
1022
1023
  static void rua_newtable_from_obj(lua_State *L, VALUE obj, struct rua_state *R) {
1023
1024
  VALUE methods, name, method;
1024
- int i, tblidx;
1025
+ int i, tblidx, prxidx;
1025
1026
 
1027
+ lua_newtable(L);
1028
+ prxidx = lua_gettop(L);
1026
1029
  lua_newtable(L);
1027
1030
  tblidx = lua_gettop(L);
1028
1031
  methods = rb_check_convert_type(obj, T_ARRAY, "Array", "methods");
1029
1032
 
1030
1033
  lua_pushstring(L, REF_RBOBJ);
1031
1034
  lua_pushlightuserdata(L, (void *) obj);
1032
- rua_set_finalizer(L, -1, obj, R);
1035
+ rua_setmeta2(L, -1, "__gc", rua_finalize_rbobj, 2, obj, R);
1033
1036
  lua_rawset(L, tblidx);
1034
1037
  rb_hash_aset(R->refs, obj, Qtrue);
1035
1038
 
@@ -1046,6 +1049,47 @@ static void rua_newtable_from_obj(lua_State *L, VALUE obj, struct rua_state *R)
1046
1049
  rua_pushrbval(L, method, R);
1047
1050
  lua_rawset(L, tblidx);
1048
1051
  }
1052
+
1053
+ lua_pushvalue(L, -1);
1054
+ rua_setmeta(L, prxidx, "__index", rua_getobject_event, 1);
1055
+ rua_setmeta(L, prxidx, "__newindex", rua_setobject_event, 1);
1056
+ }
1057
+
1058
+ static int rua_getobject_event(lua_State *L) {
1059
+ int tblidx;
1060
+
1061
+ tblidx = lua_upvalueindex(1);
1062
+ lua_rawget(L, tblidx);
1063
+ return 1;
1064
+ }
1065
+
1066
+ static int rua_setobject_event(lua_State *L) {
1067
+ const char *key;
1068
+ size_t keylen;
1069
+ char *setter;
1070
+ int tblidx;
1071
+
1072
+ tblidx = lua_upvalueindex(1);
1073
+
1074
+ key = lua_tostring(L, -2);
1075
+ keylen = strlen(key);
1076
+ setter = alloca(keylen + 2);
1077
+ memcpy(setter, key, keylen);
1078
+ setter[keylen] = '=';
1079
+ setter[keylen + 1] = '\0';
1080
+
1081
+ lua_pushstring(L, setter);
1082
+ lua_rawget(L, tblidx);
1083
+
1084
+ if (lua_isfunction(L, -1)) {
1085
+ lua_pushvalue(L, -2);
1086
+ lua_call(L, 1, 0);
1087
+ } else {
1088
+ lua_pop(L, 1);
1089
+ lua_rawset(L, tblidx);
1090
+ }
1091
+
1092
+ return 0;
1049
1093
  }
1050
1094
 
1051
1095
  static int rua_proc_call(lua_State *L) {
@@ -1213,10 +1257,10 @@ static const char *rua_classname_ptr(VALUE v) {
1213
1257
  return StringValuePtr(klassname);
1214
1258
  }
1215
1259
 
1216
- static void rua_set_finalizer(lua_State *L, int idx, VALUE rbobj, struct rua_state *R) {
1217
- int pretop, objidx, tblidx;
1260
+ static void rua_setmeta(lua_State *L, int idx, const char *key, lua_CFunction f, int n) {
1261
+ int basetop, objidx, tblidx, i;
1218
1262
 
1219
- pretop = lua_gettop(L);
1263
+ basetop = lua_gettop(L) - n;
1220
1264
  lua_pushvalue(L, idx);
1221
1265
  objidx = lua_gettop(L);
1222
1266
 
@@ -1227,14 +1271,37 @@ static void rua_set_finalizer(lua_State *L, int idx, VALUE rbobj, struct rua_sta
1227
1271
  }
1228
1272
 
1229
1273
  tblidx = lua_gettop(L);
1230
- lua_pushstring(L, "__gc");
1274
+ lua_pushstring(L, key);
1231
1275
 
1232
- lua_pushlightuserdata(L, (void *) rbobj);
1233
- lua_pushlightuserdata(L, R);
1234
- lua_pushcclosure(L, rua_finalize_rbobj, 2);
1276
+ for (i = 1; i <= n; i++) {
1277
+ lua_pushvalue(L, basetop + i);
1278
+ }
1279
+
1280
+ if (n > 0) {
1281
+ lua_pushcclosure(L, f, n);
1282
+ } else {
1283
+ lua_pushcfunction(L, f);
1284
+ }
1235
1285
 
1236
1286
  lua_rawset(L, tblidx);
1237
- lua_pop(L, lua_gettop(L) - pretop);
1287
+ lua_pop(L, lua_gettop(L) - basetop);
1288
+ }
1289
+
1290
+ static void rua_setmeta2(lua_State *L, int idx, const char *key, lua_CFunction f, int n, ...) {
1291
+ va_list argp;
1292
+ int i;
1293
+
1294
+ va_start(argp, n);
1295
+
1296
+ for (i = 0; i < n; i++) {
1297
+ lua_pushlightuserdata(L, va_arg(argp, void*));
1298
+ }
1299
+
1300
+ if (idx < 0) {
1301
+ idx -= n;
1302
+ }
1303
+
1304
+ rua_setmeta(L, idx, key, f, n);
1238
1305
  }
1239
1306
 
1240
1307
  static int rua_finalize_rbobj(lua_State *L) {
data/ext/rua.h CHANGED
@@ -99,6 +99,8 @@ static void rua_pushrbval(lua_State *L, VALUE rbval, struct rua_state *R);
99
99
  static void rua_newtable_from_ary(lua_State *L, VALUE ary, struct rua_state *R);
100
100
  static void rua_newtable_from_hash(lua_State *L, VALUE hash, struct rua_state *R);
101
101
  static void rua_newtable_from_obj(lua_State *L, VALUE obj, struct rua_state *R);
102
+ static int rua_getobject_event(lua_State *L);
103
+ static int rua_setobject_event(lua_State *L);
102
104
  static int rua_proc_call(lua_State *L);
103
105
  static VALUE _rua_proc_call(VALUE args);
104
106
  static VALUE _rua_proc_call_with_block(VALUE args);
@@ -112,8 +114,9 @@ static VALUE rua_to_s(VALUE v);
112
114
  static const char *rua_to_sptr(VALUE v);
113
115
  static VALUE rua_classname(VALUE v);
114
116
  static const char *rua_classname_ptr(VALUE v);
117
+ static void rua_setmeta(lua_State *L, int idx, const char *key, lua_CFunction f, int n);
118
+ static void rua_setmeta2(lua_State *L, int idx, const char *key, lua_CFunction f, int n, ...);
115
119
  static int rua_finalize_rbobj(lua_State *L);
116
- static void rua_set_finalizer(lua_State *L, int idx, VALUE rbobj, struct rua_state *R);
117
120
  static VALUE rua_iconv(const char *to, const char *from, VALUE in);
118
121
 
119
122
  #endif
metadata CHANGED
@@ -1,51 +1,58 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.9.2
3
- specification_version: 1
4
2
  name: rua
5
3
  version: !ruby/object:Gem::Version
6
- version: 0.3.5
7
- date: 2007-12-10 00:00:00 +09:00
8
- summary: Rua is a library for using Lua under Ruby.
9
- require_paths:
10
- - lib
11
- email: sgwr_dts@yahoo.co.jp
12
- homepage: http://rua.rubyforge.org
13
- rubyforge_project:
14
- description:
15
- autorequire:
16
- default_executable:
17
- bindir: bin
18
- has_rdoc: true
19
- required_ruby_version: !ruby/object:Gem::Version::Requirement
20
- requirements:
21
- - - ">"
22
- - !ruby/object:Gem::Version
23
- version: 0.0.0
24
- version:
25
- platform: ruby
26
- signing_key:
27
- cert_chain:
28
- post_install_message:
4
+ version: 0.3.7
5
+ platform: ""
29
6
  authors:
30
7
  - winebarrel
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2007-12-26 00:00:00 +09:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description:
17
+ email: sgwr_dts@yahoo.co.jp
18
+ executables: []
19
+
20
+ extensions:
21
+ - ext/extconf.rb
22
+ extra_rdoc_files:
23
+ - README.txt
24
+ - ext/rua.c
31
25
  files:
32
26
  - README.txt
33
27
  - ext/rua.c
34
28
  - ext/rua.h
35
29
  - ext/extconf.rb
36
- test_files: []
37
-
30
+ has_rdoc: true
31
+ homepage: http://rua.rubyforge.org
32
+ post_install_message:
38
33
  rdoc_options:
39
34
  - --title
40
35
  - Rua - library for using Lua under Ruby.
41
- extra_rdoc_files:
42
- - README.txt
43
- - ext/rua.c
44
- executables: []
45
-
46
- extensions:
47
- - ext/extconf.rb
36
+ require_paths:
37
+ - lib
38
+ required_ruby_version: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: "0"
43
+ version:
44
+ required_rubygems_version: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: "0"
49
+ version:
48
50
  requirements: []
49
51
 
50
- dependencies: []
52
+ rubyforge_project:
53
+ rubygems_version: 0.9.5
54
+ signing_key:
55
+ specification_version: 2
56
+ summary: Rua is a library for using Lua under Ruby.
57
+ test_files: []
51
58