transparent-lua 0.2 → 0.3

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
- YmYyZGQ3NzY0YzU1ZDBiY2I1YmE5YTA2MmI5ZjFlMGFlYmVhMWY0Mw==
4
+ MGMyY2IzNDkyY2I1NTVlYzU2YTlkMjdjM2UyM2U4ZjZmM2YyMTAyMg==
5
5
  data.tar.gz: !binary |-
6
- ODU4YjU0YWUxMWVmOWNiOWZiNDU5ZmEwMjBhODcyZGU2MzQzYzdiZg==
6
+ NjIwMzJjYjI1ZDBhMzQwNTJiNWY2ZWYwOGMzZjdhMjI1M2JjYzIzNg==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- NzQwZmExYjYxNzRiZTBiOGNmOGU1MjQ0NGM4ODJiN2FlMTcyOWQ3OGZmYzEz
10
- NmU5ZjgwOGI1NDhkNDNmYjEwM2Y4ZTExYTAzNTc3ODc4NTE0ZmI5YTljYzVj
11
- NjFlN2Q0MGNkMDQwNzY2YzNkNzFlN2M0ZjlkNjE3NTQzYjk0YjI=
9
+ ZDAzMTgwMjA5ZWZmYTMwMjUxNTU3ZmM5YzRkNjg5YmZkMzU3ZWNhZjBkN2U4
10
+ NGRkOGZmMDZlNWU4NTM5YTQ4ZTg5Y2NiMmZhMTk2ODJkNGE2NzUzZDgzMjQ1
11
+ MWNmOTc0Mjg1MWM4NTcwN2UyM2MxOTBiM2RmYTJkYjdhYTIwNTU=
12
12
  data.tar.gz: !binary |-
13
- MjQwMWJlZTFjMjUzMjAxMGJiMjk2ZjFhZjZmYzJmYTNlMzlmYmQzNjM1YTEw
14
- NWYyNWRlZGMzODY0MjZlZGVmODExMTI5NWRhMGE3N2U1MjFhNzIwMDg0Y2Vk
15
- MzQ2OTRjYWY5MzUwZjVhMWEwNjU3YjA5NGY5YzkxNmZkN2U0N2I=
13
+ Y2M2ZDBiNDdkMTllN2I2OGFhZDgxNTMzNGE1MWY4YzhjNzUxZDhjOWExNjJi
14
+ NmExY2VkZjJjYzUwZmRkNGY2Y2UzODM5ZTI3YmZiZDFjNTFmZGYwMTZjNzI2
15
+ MzA3NGVkYzMwNmE0NTYyYWYyMWFkZmVhODNkODU4M2Q3ODQ0MDc=
@@ -8,7 +8,7 @@ Feature: Sandbox exposition
8
8
  Then it should return "OK"
9
9
 
10
10
  Scenario Outline: Exposing member class methods to the lua script
11
- Given an sandbox with an empty member class
11
+ Given a sandbox with an empty member class
12
12
  And the following method definition as part of the member class: def <method_signature>; <method_body>; end;
13
13
  And the following line as Lua script: return(<method_call>);
14
14
  When I execute the script
@@ -73,4 +73,14 @@ Feature: Sandbox exposition
73
73
  When I execute the script
74
74
  Then the result of @sandbox.struct.values should include('Hi')
75
75
 
76
+ Scenario: Passing instances to methods as arguments
77
+ Given a sandbox with an empty member class
78
+ And the following code executed in the sandbox: def ret(param); param.inspect; end
79
+ And the following Lua script:
80
+ """
81
+ return(ret(member_class));
82
+ """
83
+ When I execute the script
84
+ Then it should return "#<Sandbox Member Class>"
85
+
76
86
 
@@ -10,7 +10,7 @@ Given(/^an empty sandbox$/) do
10
10
  end
11
11
  end
12
12
 
13
- Given(/^an sandbox with an empty member class$/) do
13
+ Given(/^an? sandbox with an empty member class$/) do
14
14
  @member_class = Class.new do
15
15
  def inspect
16
16
  '#<Sandbox Member Class>'
@@ -57,7 +57,7 @@ class TransparentLua
57
57
  '__index' => index_table(object),
58
58
  '__newindex' => newindex_table(object),
59
59
  }
60
- metatable(metatable)
60
+ delegation_table(object, metatable)
61
61
  end
62
62
 
63
63
  def newindex_table(object)
@@ -93,16 +93,25 @@ class TransparentLua
93
93
 
94
94
  # @param [Method] method
95
95
  def method_table(method)
96
- metatable(
96
+ delegation_table(
97
97
  '__call' => ->(t, *args) do
98
- getter_table(method.call(*args))
98
+ converted_args = args.collect do |arg|
99
+ case arg
100
+ when Lua::Table
101
+ ObjectSpace._id2ref(Integer(arg.__rb_object_id))
102
+ else
103
+ arg
104
+ end
105
+ end
106
+ getter_table(method.call(*converted_args))
99
107
  end
100
108
  )
101
109
  end
102
110
 
103
- def metatable(hash)
104
- tab = Lua::Table.new(@state)
105
- tab.__metatable = hash
111
+ def delegation_table(object = nil, hash)
112
+ tab = Lua::Table.new(@state)
113
+ tab.__rb_object_id = -> { object.__id__ } if object
114
+ tab.__metatable = hash
106
115
  tab
107
116
  end
108
117
 
@@ -1,3 +1,3 @@
1
1
  class TransparentLua
2
- VERSION = 0.2
2
+ VERSION = 0.3
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.2'
4
+ version: '0.3'
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-03 00:00:00.000000000 Z
11
+ date: 2015-07-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rlua