transparent-lua 0.5 → 0.6

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.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZWRjNjZkZGZiYzRlOTZjMTkzNGU1N2Q0N2IxZGJlNWEzZGVjZmM3Ng==
4
+ ZTlhMmE0NTMxZTY0ZDZjZjMzNzM3ZWY0YzdhMWFlYmNmNDNjNDQxZQ==
5
5
  data.tar.gz: !binary |-
6
- OWIwZjIwYTgxMTQ1NmQ3NTU0ZTViZjJmOTdmYTY4MzMxNzkyYmNmZA==
6
+ Y2UzNDM3MGFkNjYyNzkzNDI5YmJiNjkwZDRiOTNhYjU3NTdlM2Q0Mw==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- MDdjOTQ2MDI0YzVhYjNiMWQzNDA4NDc1Y2Q1NjBjZjQxM2Y1OGVhNzQyNTQy
10
- Yjc5NjdkMWY0MDdkNmUyNDMyYTM2ZGZkMGIwN2U4Y2FmZjc2MWEyZjJkODdj
11
- Njk2YmJkNmQ0ZGQ2N2IyZWM0Y2QwMDU0ZmQ5MGFmMTVmN2U2MzY=
9
+ YTNkNWExYWEyZGVkYzgxMGY3NmNmOWVjYzI4MDk4MzUwNGI5ZDlhMGZjYjZj
10
+ NzQ2YjAzYWU0NTI4ZjA5NGMwZWI2OGQwYzk0NTMyMTAwNTU3NWE1Y2RkMzhl
11
+ NzBkODBkNTRlNDliZDAyMDJkNTk5YTk2NTBhYjI0ZGE0OTgzNjM=
12
12
  data.tar.gz: !binary |-
13
- YjljNjJkMWVhMzU3MTdiN2ZkZTIyMjBhMDA1NjliNzljMTdkNjU1NTcxOGMz
14
- MGQ5YzQzMjExY2UyNDkwMzkzNTQ4YTQ3NTk5N2U2YWU3NjIzMjI2YWJkODFj
15
- NWM2NDdhMGQ2NTkwMzY5ZjE0MzFhOGFlMjA4Mzk1YWVmODViNTU=
13
+ NzM4ZjA1MTZiNGE1ZWJkMzVlNWQ0OTBlZjVjMTE4MjM3NGY5NTc0YzhhNzIy
14
+ MDFiYTM2NzdmZTkzZTI3ZGY0NDdjZTE4MDUwN2RmYjYzYzkwMmVhOWUyMzJl
15
+ OTYwMjE1MjdmM2Y4ZjU1ZjY4Zjc1NTkxYTA3NDE5Y2RlZGY1ZDg=
@@ -83,6 +83,16 @@ Feature: Sandbox exposition
83
83
  When I execute the script
84
84
  Then it should return "#<Sandbox Member Class>"
85
85
 
86
+ Scenario: Passing plain lua tables to methods as arguments
87
+ Given an empty sandbox
88
+ And the following code executed in the sandbox: def ret(param); param.inspect; end
89
+ And the following Lua script:
90
+ """
91
+ return(ret({foo = "bar"}));
92
+ """
93
+ When I execute the script
94
+ Then it should return {'foo' => 'bar'}.inspect
95
+
86
96
  Scenario: Requiring virtual files
87
97
  Given an empty sandbox
88
98
  And the following code executed in the sandbox:
@@ -107,3 +117,4 @@ Feature: Sandbox exposition
107
117
  When I execute the script
108
118
  Then it should return "Virtual return value"
109
119
 
120
+
@@ -115,7 +115,7 @@ class TransparentLua
115
115
  end
116
116
 
117
117
  def get_method(object, method_name)
118
- fail NoMethodError, "#{object}##{method_name.to_s} is not a method (but might me a valid message which is not supported)" unless object.methods.include? method_name.to_sym
118
+ fail NoMethodError, "#{object}##{method_name.to_s} is not a method (but might be a valid message which is not supported)" unless object.methods.include? method_name.to_sym
119
119
  object.method(method_name.to_sym)
120
120
  end
121
121
 
@@ -124,13 +124,9 @@ class TransparentLua
124
124
  delegation_table(
125
125
  '__call' => ->(t, *args) do
126
126
  converted_args = args.collect do |arg|
127
- case arg
128
- when Lua::Table
129
- ObjectSpace._id2ref(Integer(arg.__rb_object_id))
130
- else
131
- arg
132
- end
127
+ lua2rb(arg)
133
128
  end
129
+
134
130
  getter_table(method.call(*converted_args))
135
131
  end
136
132
  )
@@ -145,6 +141,8 @@ class TransparentLua
145
141
 
146
142
  def lua2rb(v)
147
143
  case v
144
+ when ->(t) { has_rb_object_id?(t) }
145
+ ObjectSpace._id2ref(Integer(v.__rb_object_id))
148
146
  when ->(t) { Lua::Table === t && t.to_hash.keys.all? { |k| k.is_a? Numeric } }
149
147
  v.to_hash.values
150
148
  when Lua::Table
@@ -153,4 +151,11 @@ class TransparentLua
153
151
  v
154
152
  end
155
153
  end
154
+
155
+ def has_rb_object_id?(o)
156
+ o.__rb_object_id
157
+ true
158
+ rescue NoMethodError
159
+ false
160
+ end
156
161
  end
@@ -1,3 +1,3 @@
1
1
  class TransparentLua
2
- VERSION = 0.5
2
+ VERSION = 0.6
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: transparent-lua
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.5'
4
+ version: '0.6'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christian Haase
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-13 00:00:00.000000000 Z
11
+ date: 2015-07-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rlua