rua 0.3.7 → 0.3.8

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/README.txt +5 -0
  2. data/ext/rua.c +28 -2
  3. metadata +4 -4
data/README.txt CHANGED
@@ -27,6 +27,8 @@ http://storehouse.sakura.ne.jp/rua/
27
27
  class MyClass
28
28
  def val=(v); @val = v; end
29
29
  def val; @val; end
30
+ def [](k); "#{k}->#{@val}"; end
31
+ def []=(k, v); @val = "#{k}:#{v}"; end
30
32
  end
31
33
 
32
34
  rua = Rua.new(:all)
@@ -65,6 +67,9 @@ http://storehouse.sakura.ne.jp/rua/
65
67
  my_obj = MyClass.new()
66
68
  my_obj.val = 'my_obj.val'
67
69
  print(my_obj.val())
70
+ print(my_obj['foo'])
71
+ my_obj['bar'] = 'zoo'
72
+ print(my_obj.val())
68
73
 
69
74
  f = function()
70
75
  print('f() called.')
data/ext/rua.c CHANGED
@@ -21,7 +21,7 @@ __declspec(dllexport) void Init_rua(void);
21
21
 
22
22
  #include "rua.h"
23
23
 
24
- #define VERSION "0.3.7"
24
+ #define VERSION "0.3.8"
25
25
  #define REF_RBOBJ "self"
26
26
 
27
27
  #define ICONV_JIS "ISO-2022-JP"
@@ -1059,7 +1059,23 @@ static int rua_getobject_event(lua_State *L) {
1059
1059
  int tblidx;
1060
1060
 
1061
1061
  tblidx = lua_upvalueindex(1);
1062
+ lua_pushvalue(L, -1);
1062
1063
  lua_rawget(L, tblidx);
1064
+
1065
+ if (lua_isnil(L, -1)) {
1066
+ lua_pop(L, 1);
1067
+ lua_pushstring(L, "[]");
1068
+ lua_rawget(L, tblidx);
1069
+
1070
+ if (lua_isfunction(L, -1)) {
1071
+ lua_pushvalue(L, -2);
1072
+ lua_call(L, 1, 1);
1073
+ } else {
1074
+ lua_pop(L, 1);
1075
+ lua_pushnil(L);
1076
+ }
1077
+ }
1078
+
1063
1079
  return 1;
1064
1080
  }
1065
1081
 
@@ -1086,7 +1102,17 @@ static int rua_setobject_event(lua_State *L) {
1086
1102
  lua_call(L, 1, 0);
1087
1103
  } else {
1088
1104
  lua_pop(L, 1);
1089
- lua_rawset(L, tblidx);
1105
+ lua_pushstring(L, "[]=");
1106
+ lua_rawget(L, tblidx);
1107
+
1108
+ if (lua_isfunction(L, -1)) {
1109
+ lua_pushvalue(L, -3);
1110
+ lua_pushvalue(L, -3);
1111
+ lua_call(L, 2, 0);
1112
+ } else {
1113
+ lua_pop(L, 1);
1114
+ lua_rawset(L, tblidx);
1115
+ }
1090
1116
  }
1091
1117
 
1092
1118
  return 0;
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rua
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.7
5
- platform: ""
4
+ version: 0.3.8
5
+ platform: ruby
6
6
  authors:
7
7
  - winebarrel
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2007-12-26 00:00:00 +09:00
12
+ date: 2007-12-28 00:00:00 +09:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -50,7 +50,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
50
50
  requirements: []
51
51
 
52
52
  rubyforge_project:
53
- rubygems_version: 0.9.5
53
+ rubygems_version: 1.0.1
54
54
  signing_key:
55
55
  specification_version: 2
56
56
  summary: Rua is a library for using Lua under Ruby.