transparent-lua 0.1 → 0.2
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
|
-
|
4
|
+
YmYyZGQ3NzY0YzU1ZDBiY2I1YmE5YTA2MmI5ZjFlMGFlYmVhMWY0Mw==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
ODU4YjU0YWUxMWVmOWNiOWZiNDU5ZmEwMjBhODcyZGU2MzQzYzdiZg==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
NzQwZmExYjYxNzRiZTBiOGNmOGU1MjQ0NGM4ODJiN2FlMTcyOWQ3OGZmYzEz
|
10
|
+
NmU5ZjgwOGI1NDhkNDNmYjEwM2Y4ZTExYTAzNTc3ODc4NTE0ZmI5YTljYzVj
|
11
|
+
NjFlN2Q0MGNkMDQwNzY2YzNkNzFlN2M0ZjlkNjE3NTQzYjk0YjI=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MjQwMWJlZTFjMjUzMjAxMGJiMjk2ZjFhZjZmYzJmYTNlMzlmYmQzNjM1YTEw
|
14
|
+
NWYyNWRlZGMzODY0MjZlZGVmODExMTI5NWRhMGE3N2U1MjFhNzIwMDg0Y2Vk
|
15
|
+
MzQ2OTRjYWY5MzUwZjVhMWEwNjU3YjA5NGY5YzkxNmZkN2U0N2I=
|
@@ -62,4 +62,15 @@ Feature: Sandbox exposition
|
|
62
62
|
When I execute the script
|
63
63
|
Then it should return "HELLO"
|
64
64
|
|
65
|
+
Scenario: Setting attributes of members
|
66
|
+
Given an empty sandbox
|
67
|
+
And the following code executed in the sandbox: def struct; @struct ||= Struct.new(:attr).new; end
|
68
|
+
And the following Lua script:
|
69
|
+
"""
|
70
|
+
s = struct
|
71
|
+
s.attr = 'Hi'
|
72
|
+
"""
|
73
|
+
When I execute the script
|
74
|
+
Then the result of @sandbox.struct.values should include('Hi')
|
75
|
+
|
65
76
|
|
@@ -32,7 +32,7 @@ Given(/^an sandbox with an empty member class$/) do
|
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
|
-
And(/^the following method definition as part of the sandbox: (.*)$/) do |method_definition|
|
35
|
+
And(/^the following (?:method definition as part of|code executed in) the sandbox: (.*)$/) do |method_definition|
|
36
36
|
@sandbox_class.class_eval(method_definition)
|
37
37
|
end
|
38
38
|
|
@@ -44,4 +44,7 @@ And(/^the following line as Lua script: (.*)$/) do |script|
|
|
44
44
|
@script = String(script).strip
|
45
45
|
end
|
46
46
|
|
47
|
+
And(/^the following Lua script:$/) do |script|
|
48
|
+
@script = String(script).strip
|
49
|
+
end
|
47
50
|
|
@@ -9,3 +9,8 @@ Then(/^the attribute "([^"]*)" of the sandbox is (.*)$/) do |attribute, expected
|
|
9
9
|
|
10
10
|
expect(@sandbox.public_send(attribute.to_sym)).to eq(expected_return_value)
|
11
11
|
end
|
12
|
+
|
13
|
+
|
14
|
+
Then(/^the result of (.+) should (.*)$/) do |subject, expectation|
|
15
|
+
expect(instance_eval(String(subject))).to eval(expectation)
|
16
|
+
end
|
data/lib/transparent_lua.rb
CHANGED
@@ -23,9 +23,9 @@ class TransparentLua
|
|
23
23
|
# The sandbox must store the values itself or an error will be raised.
|
24
24
|
# When false the locals are not reflected in the sandbox
|
25
25
|
def initialize(sandbox, options = {})
|
26
|
-
@sandbox
|
27
|
-
@state
|
28
|
-
leak_locals
|
26
|
+
@sandbox = sandbox
|
27
|
+
@state = options.fetch(:state) { Lua::State.new }
|
28
|
+
leak_locals = options.fetch(:leak_globals) { false }
|
29
29
|
setup(leak_locals)
|
30
30
|
end
|
31
31
|
|
@@ -53,7 +53,10 @@ class TransparentLua
|
|
53
53
|
return object
|
54
54
|
end
|
55
55
|
|
56
|
-
metatable = {
|
56
|
+
metatable = {
|
57
|
+
'__index' => index_table(object),
|
58
|
+
'__newindex' => newindex_table(object),
|
59
|
+
}
|
57
60
|
metatable(metatable)
|
58
61
|
end
|
59
62
|
|