sweet-moon 0.0.2 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +3 -0
- data/README.md +197 -16
- data/components/injections/injections_503.rb +2 -1
- data/components/injections/injections_514.rb +2 -1
- data/components/injections/injections_542.rb +2 -1
- data/components/interpreters/50/function.rb +14 -47
- data/components/interpreters/50/interpreter.rb +50 -28
- data/components/interpreters/50/reader.rb +2 -60
- data/components/interpreters/50/table.rb +19 -54
- data/components/interpreters/50/writer.rb +2 -40
- data/components/interpreters/51/function.rb +3 -46
- data/components/interpreters/51/interpreter.rb +37 -26
- data/components/interpreters/51/reader.rb +2 -60
- data/components/interpreters/51/table.rb +2 -55
- data/components/interpreters/51/writer.rb +2 -40
- data/components/interpreters/54/function.rb +82 -23
- data/components/interpreters/54/interpreter.rb +35 -22
- data/components/interpreters/54/reader.rb +20 -17
- data/components/interpreters/54/table.rb +25 -19
- data/components/interpreters/54/writer.rb +11 -11
- data/config/tests.sample.yml +13 -9
- data/controllers/state.rb +47 -12
- data/dsl/errors.rb +9 -1
- data/dsl/fennel.rb +2 -0
- data/dsl/state.rb +9 -3
- data/logic/interpreters/interpreter_50.rb +1 -0
- data/logic/interpreters/interpreter_54.rb +5 -5
- data/logic/spec.rb +1 -1
- metadata +2 -2
@@ -1,86 +1,99 @@
|
|
1
1
|
require_relative '../../../logic/interpreters/interpreter_54'
|
2
2
|
|
3
|
+
require_relative 'function'
|
3
4
|
require_relative 'reader'
|
4
|
-
require_relative 'writer'
|
5
5
|
require_relative 'table'
|
6
|
+
require_relative 'writer'
|
6
7
|
|
7
8
|
module Component
|
8
9
|
module V54
|
9
10
|
Interpreter = {
|
10
11
|
version: Logic::V54::Interpreter[:version],
|
12
|
+
logic: Logic::V54,
|
11
13
|
|
12
14
|
create_state!: ->(api) {
|
13
15
|
state = api.luaL_newstate
|
14
|
-
{ state:
|
16
|
+
{ state: { lua: state, avoid_gc: [], ruby_error_info: nil },
|
17
|
+
error: state ? nil : :MemoryAllocation }
|
15
18
|
},
|
16
19
|
|
17
20
|
open_standard_libraries!: ->(api, state) {
|
18
|
-
api.luaL_openlibs(state)
|
21
|
+
api.luaL_openlibs(state[:lua])
|
19
22
|
{ state: state }
|
20
23
|
},
|
21
24
|
|
22
25
|
load_file_and_push_chunck!: ->(api, state, path) {
|
23
|
-
result = api.luaL_loadfile(state, path)
|
26
|
+
result = api.luaL_loadfile(state[:lua], path)
|
24
27
|
{ state: state, error: Interpreter[:_error].(api, state, result, pull: true) }
|
25
28
|
},
|
26
29
|
|
27
30
|
push_chunk!: ->(api, state, value) {
|
28
|
-
result = api.luaL_loadstring(state, value)
|
31
|
+
result = api.luaL_loadstring(state[:lua], value)
|
29
32
|
{ state: state, error: Interpreter[:_error].(api, state, result, pull: true) }
|
30
33
|
},
|
31
34
|
|
32
|
-
set_table!: ->(api, state
|
33
|
-
|
35
|
+
set_table!: ->(api, state) {
|
36
|
+
result = api.lua_settable(state[:lua], -3)
|
37
|
+
|
38
|
+
api.lua_settop(state[:lua], -2)
|
39
|
+
|
40
|
+
{ state: state,
|
41
|
+
error: Interpreter[:_error].(api, state, result, pull: false) }
|
34
42
|
},
|
35
43
|
|
36
44
|
push_value!: ->(api, state, value) {
|
37
|
-
Writer[:push!].(api, state, value)
|
45
|
+
Writer[:push!].(api, state, Component::V54, value)
|
38
46
|
{ state: state }
|
39
47
|
},
|
40
48
|
|
41
49
|
pop_and_set_as!: ->(api, state, variable) {
|
42
|
-
api.lua_setglobal(state, variable)
|
50
|
+
api.lua_setglobal(state[:lua], variable)
|
43
51
|
{ state: state }
|
44
52
|
},
|
45
53
|
|
46
54
|
get_variable_and_push!: ->(api, state, variable, key = nil) {
|
47
|
-
api.lua_getglobal(state, variable.to_s)
|
55
|
+
api.lua_getglobal(state[:lua], variable.to_s)
|
48
56
|
|
49
57
|
unless key.nil?
|
50
|
-
if api.lua_typename(state,
|
51
|
-
|
58
|
+
if api.lua_typename(state[:lua],
|
59
|
+
api.lua_type(state[:lua], -1)).read_string == 'table'
|
60
|
+
Table[:read_field!].(api, state, Component::V54, key, -1)
|
52
61
|
else
|
53
|
-
api.lua_pushnil(state)
|
62
|
+
api.lua_pushnil(state[:lua])
|
54
63
|
end
|
55
64
|
end
|
56
65
|
|
57
|
-
{ state: state }
|
66
|
+
{ state: state, extra_pop: true }
|
58
67
|
},
|
59
68
|
|
60
69
|
call!: ->(api, state, inputs = 0, outputs = 1) {
|
61
|
-
result = api.lua_pcall(state, inputs, outputs, 0)
|
70
|
+
result = api.lua_pcall(state[:lua], inputs, outputs, 0)
|
62
71
|
{ state: state, error: Interpreter[:_error].(api, state, result, pull: true) }
|
63
72
|
},
|
64
73
|
|
65
74
|
read_and_pop!: ->(api, state, stack_index = -1, extra_pop: false) {
|
66
|
-
result = Component::V54::Reader[:read!].(api, state,
|
75
|
+
result = Component::V54::Reader[:read!].(api, state, Component::V54,
|
76
|
+
stack_index)
|
67
77
|
|
68
|
-
api.lua_settop(state, -2) if result[:pop]
|
69
|
-
api.lua_settop(state, -2) if extra_pop
|
78
|
+
api.lua_settop(state[:lua], -2) if result[:pop]
|
79
|
+
api.lua_settop(state[:lua], -2) if extra_pop
|
70
80
|
|
71
81
|
{ state: state, output: result[:value] }
|
72
82
|
},
|
73
83
|
|
74
84
|
read_all!: ->(api, state) {
|
75
|
-
result = Reader[:read_all!].(api, state)
|
85
|
+
result = Reader[:read_all!].(api, state, Component::V54)
|
76
86
|
|
77
87
|
{ state: state, output: result }
|
78
88
|
},
|
79
89
|
|
80
90
|
destroy_state!: ->(api, state) {
|
81
|
-
result = api.lua_close(state)
|
91
|
+
result = api.lua_close(state[:lua])
|
92
|
+
|
93
|
+
state.delete(:lua)
|
94
|
+
state.delete(:avoid_gc)
|
82
95
|
|
83
|
-
{ state: nil, error: Interpreter[:_error].(api,
|
96
|
+
{ state: nil, error: Interpreter[:_error].(api, nil, result) }
|
84
97
|
},
|
85
98
|
|
86
99
|
_error: ->(api, state, code, options = {}) {
|
@@ -89,7 +102,7 @@ module Component
|
|
89
102
|
] || :error
|
90
103
|
|
91
104
|
if code.is_a?(Numeric) && code >= 2
|
92
|
-
return { status: status } unless options[:pull]
|
105
|
+
return { status: status } unless options[:pull] && state
|
93
106
|
|
94
107
|
{ status: status,
|
95
108
|
value: Interpreter[:read_and_pop!].(api, state, -1)[:output] }
|
@@ -7,58 +7,61 @@ require_relative 'table'
|
|
7
7
|
module Component
|
8
8
|
module V54
|
9
9
|
Reader = {
|
10
|
-
read_all!: ->(api, state) {
|
11
|
-
(1..api.lua_gettop(state)).map do
|
12
|
-
Interpreter[:read_and_pop!].(api, state)[:output]
|
10
|
+
read_all!: ->(api, state, component) {
|
11
|
+
(1..api.lua_gettop(state[:lua])).map do
|
12
|
+
component::Interpreter[:read_and_pop!].(api, state)[:output]
|
13
13
|
end.reverse
|
14
14
|
},
|
15
15
|
|
16
|
-
read!: ->(api, state, stack_index = -1) {
|
17
|
-
stack_index = api.lua_gettop(state) if stack_index == -1
|
16
|
+
read!: ->(api, state, component, stack_index = -1) {
|
17
|
+
stack_index = api.lua_gettop(state[:lua]) if stack_index == -1
|
18
18
|
|
19
|
-
type = api.lua_typename(
|
19
|
+
type = api.lua_typename(
|
20
|
+
state[:lua], api.lua_type(state[:lua], stack_index)
|
21
|
+
).read_string
|
20
22
|
|
21
23
|
case type
|
22
24
|
when 'string'
|
23
|
-
Reader[:read_string!].(api, state, stack_index)
|
25
|
+
component::Reader[:read_string!].(api, state, stack_index)
|
24
26
|
when 'number'
|
25
|
-
Reader[:read_number!].(api, state, stack_index)
|
27
|
+
component::Reader[:read_number!].(api, state, stack_index)
|
26
28
|
when 'no value'
|
27
29
|
{ value: nil, pop: true, type: type }
|
28
30
|
when 'nil'
|
29
31
|
{ value: nil, pop: true }
|
30
32
|
when 'boolean'
|
31
|
-
Reader[:read_boolean!].(api, state, stack_index)
|
33
|
+
component::Reader[:read_boolean!].(api, state, stack_index)
|
32
34
|
when 'table'
|
33
|
-
Table[:read!].(api, state, stack_index)
|
35
|
+
component::Table[:read!].(api, state, component, stack_index)
|
34
36
|
when 'function'
|
35
|
-
Function[:read!].(api, state, stack_index)
|
37
|
+
component::Function[:read!].(api, state, component, stack_index)
|
36
38
|
else
|
37
39
|
# none nil boolean lightuserdata number
|
38
40
|
# string table function userdata thread
|
39
|
-
{ value:
|
41
|
+
{ value:
|
42
|
+
"#{type}: 0x#{api.lua_topointer(state[:lua], stack_index).address}",
|
40
43
|
type: type, pop: true }
|
41
44
|
end
|
42
45
|
},
|
43
46
|
|
44
47
|
read_string!: ->(api, state, stack_index) {
|
45
|
-
{ value: api.lua_tostring(state, stack_index).read_string,
|
48
|
+
{ value: api.lua_tostring(state[:lua], stack_index).read_string,
|
46
49
|
pop: true }
|
47
50
|
},
|
48
51
|
|
49
52
|
read_number!: ->(api, state, stack_index) {
|
50
53
|
if api.respond_to?(:lua_isinteger) &&
|
51
54
|
api.respond_to?(:lua_tointeger) &&
|
52
|
-
api.lua_isinteger(state, stack_index) == 1
|
55
|
+
api.lua_isinteger(state[:lua], stack_index) == 1
|
53
56
|
|
54
|
-
return { value: api.lua_tointeger(state, stack_index), pop: true }
|
57
|
+
return { value: api.lua_tointeger(state[:lua], stack_index), pop: true }
|
55
58
|
end
|
56
59
|
|
57
|
-
{ value: api.lua_tonumber(state, stack_index), pop: true }
|
60
|
+
{ value: api.lua_tonumber(state[:lua], stack_index), pop: true }
|
58
61
|
},
|
59
62
|
|
60
63
|
read_boolean!: ->(api, state, stack_index) {
|
61
|
-
{ value: api.lua_toboolean(state, stack_index) == 1, pop: true }
|
64
|
+
{ value: api.lua_toboolean(state[:lua], stack_index) == 1, pop: true }
|
62
65
|
}
|
63
66
|
}
|
64
67
|
end
|
@@ -6,41 +6,47 @@ require_relative 'reader'
|
|
6
6
|
module Component
|
7
7
|
module V54
|
8
8
|
Table = {
|
9
|
-
|
10
|
-
|
9
|
+
create_table!: ->(api, state, list) {
|
10
|
+
api.lua_createtable(state[:lua], list.size, 0)
|
11
|
+
},
|
12
|
+
|
13
|
+
push!: ->(api, state, component, list, stack_index = -1) {
|
14
|
+
stack_index = api.lua_gettop(state[:lua]) if stack_index == -1
|
11
15
|
|
12
|
-
|
16
|
+
component::Table[:create_table!].(api, state, list)
|
13
17
|
|
14
18
|
if list.is_a? Hash
|
15
19
|
list.each_key do |key|
|
16
|
-
Writer[:push!].(api, state, key)
|
17
|
-
Writer[:push!].(api, state, list[key])
|
18
|
-
api.lua_settable(state, stack_index + 1)
|
20
|
+
component::Writer[:push!].(api, state, component, key)
|
21
|
+
component::Writer[:push!].(api, state, component, list[key])
|
22
|
+
api.lua_settable(state[:lua], stack_index + 1)
|
19
23
|
end
|
20
24
|
else
|
21
25
|
list.each_with_index do |value, index|
|
22
|
-
Writer[:push!].(api, state, index + 1)
|
23
|
-
Writer[:push!].(api, state, value)
|
24
|
-
api.lua_settable(state, stack_index + 1)
|
26
|
+
component::Writer[:push!].(api, state, component, index + 1)
|
27
|
+
component::Writer[:push!].(api, state, component, value)
|
28
|
+
api.lua_settable(state[:lua], stack_index + 1)
|
25
29
|
end
|
26
30
|
end
|
27
31
|
},
|
28
32
|
|
29
|
-
read!: ->(api, state, stack_index) {
|
30
|
-
stack_index = api.lua_gettop(state) if stack_index == -1
|
33
|
+
read!: ->(api, state, component, stack_index) {
|
34
|
+
stack_index = api.lua_gettop(state[:lua]) if stack_index == -1
|
31
35
|
|
32
|
-
type = api.lua_typename(
|
36
|
+
type = api.lua_typename(
|
37
|
+
state[:lua], api.lua_type(state[:lua], stack_index)
|
38
|
+
).read_string
|
33
39
|
|
34
|
-
api.lua_pushnil(state)
|
40
|
+
api.lua_pushnil(state[:lua])
|
35
41
|
|
36
42
|
return nil if type != 'table'
|
37
43
|
|
38
44
|
tuples = []
|
39
45
|
|
40
|
-
while api.lua_next(state, stack_index).positive?
|
41
|
-
value = Reader[:read!].(api, state, stack_index + 2)
|
42
|
-
key = Reader[:read!].(api, state, stack_index + 1)
|
43
|
-
api.lua_settop(state, -2) if value[:pop]
|
46
|
+
while api.lua_next(state[:lua], stack_index).positive?
|
47
|
+
value = component::Reader[:read!].(api, state, component, stack_index + 2)
|
48
|
+
key = component::Reader[:read!].(api, state, component, stack_index + 1)
|
49
|
+
api.lua_settop(state[:lua], -2) if value[:pop]
|
44
50
|
|
45
51
|
tuples << [key[:value], value[:value]]
|
46
52
|
|
@@ -50,10 +56,10 @@ module Component
|
|
50
56
|
{ value: Logic::Tables[:to_hash_or_array].(tuples), pop: true }
|
51
57
|
},
|
52
58
|
|
53
|
-
read_field!: ->(api, state, expected_key, stack_index) {
|
59
|
+
read_field!: ->(api, state, _component, expected_key, stack_index) {
|
54
60
|
expected_key = expected_key.to_s if expected_key.is_a? Symbol
|
55
61
|
|
56
|
-
api.lua_getfield(state, stack_index, expected_key)
|
62
|
+
api.lua_getfield(state[:lua], stack_index, expected_key)
|
57
63
|
}
|
58
64
|
}
|
59
65
|
end
|
@@ -4,29 +4,29 @@ require_relative 'table'
|
|
4
4
|
module Component
|
5
5
|
module V54
|
6
6
|
Writer = {
|
7
|
-
push!: ->(api, state, value) {
|
8
|
-
case Writer[:_to_lua_type].(value)
|
7
|
+
push!: ->(api, state, component, value) {
|
8
|
+
case component::Writer[:_to_lua_type].(value)
|
9
9
|
when 'string'
|
10
|
-
api.lua_pushstring(state, value.to_s)
|
10
|
+
api.lua_pushstring(state[:lua], value.to_s)
|
11
11
|
when 'number'
|
12
|
-
api.lua_pushnumber(state, value)
|
12
|
+
api.lua_pushnumber(state[:lua], value)
|
13
13
|
when 'integer'
|
14
14
|
if api.respond_to? :lua_pushinteger
|
15
|
-
api.lua_pushinteger(state, value)
|
15
|
+
api.lua_pushinteger(state[:lua], value)
|
16
16
|
else
|
17
|
-
api.lua_pushnumber(state, value)
|
17
|
+
api.lua_pushnumber(state[:lua], value)
|
18
18
|
end
|
19
19
|
when 'nil'
|
20
|
-
api.lua_pushnil(state)
|
20
|
+
api.lua_pushnil(state[:lua])
|
21
21
|
when 'boolean'
|
22
|
-
api.lua_pushboolean(state, value ? 1 : 0)
|
22
|
+
api.lua_pushboolean(state[:lua], value ? 1 : 0)
|
23
23
|
when 'table'
|
24
|
-
Table[:push!].(api, state, value)
|
24
|
+
component::Table[:push!].(api, state, component, value)
|
25
25
|
when 'function'
|
26
|
-
Function[:push!].(api, state, value)
|
26
|
+
component::Function[:push!].(api, state, component, value)
|
27
27
|
else
|
28
28
|
api.lua_pushstring(
|
29
|
-
state, "#<#{value.class}:0x#{format('%016x', value.object_id)}>"
|
29
|
+
state[:lua], "#<#{value.class}:0x#{format('%016x', value.object_id)}>"
|
30
30
|
)
|
31
31
|
end
|
32
32
|
},
|
data/config/tests.sample.yml
CHANGED
@@ -1,39 +1,43 @@
|
|
1
1
|
# Available at https://github.com/gbaptista/sweet-moon-test
|
2
2
|
|
3
|
+
fennel-dev: '/home/me/sweet-moon-test/fennel/dev/?.lua'
|
4
|
+
|
3
5
|
luarocks:
|
4
|
-
|
5
|
-
|
6
|
-
|
6
|
+
path:
|
7
|
+
- /home/me/.luarocks/share/lua/5.4/?.lua
|
8
|
+
- /home/me/.luarocks/share/lua/5.4/?/init.lua
|
9
|
+
- /home/me/.luarocks/lib/lua/5.4/?.so
|
10
|
+
expected: ['supernova', 'dkjson', 'lfs']
|
7
11
|
|
8
12
|
jit:2.0.5:
|
9
13
|
description: 'Lua Jit 2.0.5 + Fennel 1.0.0'
|
10
14
|
shared_object: /home/me/sweet-moon-test/libluajit.so.2.0.5
|
11
|
-
fennel: /home/me/sweet-moon-test/fennel
|
15
|
+
fennel: /home/me/sweet-moon-test/fennel/100/?.lua
|
12
16
|
|
13
17
|
5.4.4:
|
14
18
|
description: 'Lua 5.4.4 + Fennel 1.0.0'
|
15
19
|
shared_object: /home/me/sweet-moon-test/liblua.so.5.4.4
|
16
|
-
fennel: /home/me/sweet-moon-test/fennel
|
20
|
+
fennel: /home/me/sweet-moon-test/fennel/100/?.lua
|
17
21
|
|
18
22
|
5.4.2:
|
19
23
|
description: 'Lua 5.4.2 + Fennel 1.0.0'
|
20
24
|
shared_object: /home/me/sweet-moon-test/liblua.so.5.4.2
|
21
|
-
fennel: /home/me/sweet-moon-test/fennel
|
25
|
+
fennel: /home/me/sweet-moon-test/fennel/100/?.lua
|
22
26
|
|
23
27
|
5.3.3:
|
24
28
|
description: 'Lua 5.3.3'
|
25
29
|
shared_object: /home/me/sweet-moon-test/liblua.so.5.3.3
|
26
|
-
fennel: /home/me/sweet-moon-test/fennel
|
30
|
+
fennel: /home/me/sweet-moon-test/fennel/100/?.lua
|
27
31
|
|
28
32
|
5.2.4:
|
29
33
|
description: 'Lua 5.2.4'
|
30
34
|
shared_object: /home/me/sweet-moon-test/liblua.so.5.2.4
|
31
|
-
fennel: /home/me/sweet-moon-test/fennel
|
35
|
+
fennel: /home/me/sweet-moon-test/fennel/100/?.lua
|
32
36
|
|
33
37
|
5.1.5:
|
34
38
|
description: 'Lua 5.1.5'
|
35
39
|
shared_object: /home/me/sweet-moon-test/liblua.so.5.1.5
|
36
|
-
fennel: /home/me/sweet-moon-test/fennel
|
40
|
+
fennel: /home/me/sweet-moon-test/fennel/100/?.lua
|
37
41
|
|
38
42
|
5.0.3:
|
39
43
|
description: 'Lua 5.0.3'
|
data/controllers/state.rb
CHANGED
@@ -26,23 +26,48 @@ module Controller
|
|
26
26
|
},
|
27
27
|
|
28
28
|
get!: ->(api, interpreter, state, variable, key = nil) {
|
29
|
+
if key.nil?
|
30
|
+
key = variable
|
31
|
+
variable = '_G'
|
32
|
+
end
|
33
|
+
|
34
|
+
State[:_get_key!].(api, interpreter, state, variable, key)
|
35
|
+
},
|
36
|
+
|
37
|
+
_get_key!: ->(api, interpreter, state, variable, key) {
|
29
38
|
result = State[:_check!].(
|
30
39
|
interpreter[:get_variable_and_push!].(api, state, variable, key)
|
31
40
|
)
|
32
41
|
|
33
|
-
result = State[:_check!].(
|
34
|
-
|
35
|
-
|
42
|
+
result = State[:_check!].(
|
43
|
+
interpreter[:read_and_pop!].(
|
44
|
+
api, result[:state], -1, extra_pop: result[:extra_pop]
|
45
|
+
)
|
46
|
+
)
|
36
47
|
|
37
48
|
{ state: result[:state], output: result[:output] }
|
38
49
|
},
|
39
50
|
|
40
|
-
set!: ->(api, interpreter, state, variable, value) {
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
51
|
+
set!: ->(api, interpreter, state, variable, key_or_value, value = nil) {
|
52
|
+
if value.nil?
|
53
|
+
result = State[:_check!].(interpreter[:push_value!].(api, state,
|
54
|
+
key_or_value))
|
55
|
+
|
56
|
+
result = State[:_check!].(
|
57
|
+
interpreter[:pop_and_set_as!].(api, result[:state], variable.to_s)
|
58
|
+
)
|
59
|
+
else
|
60
|
+
result = State[:_check!].(
|
61
|
+
interpreter[:get_variable_and_push!].(api, state, variable)
|
62
|
+
)
|
63
|
+
|
64
|
+
result = State[:_check!].(interpreter[:push_value!].(api, result[:state],
|
65
|
+
key_or_value))
|
66
|
+
result = State[:_check!].(interpreter[:push_value!].(api, result[:state],
|
67
|
+
value))
|
68
|
+
|
69
|
+
result = State[:_check!].(interpreter[:set_table!].(api, result[:state]))
|
70
|
+
end
|
46
71
|
|
47
72
|
{ state: result[:state], output: result[:output] }
|
48
73
|
},
|
@@ -62,10 +87,20 @@ module Controller
|
|
62
87
|
},
|
63
88
|
|
64
89
|
_check!: ->(result) {
|
90
|
+
ruby_error = result[:state] && result[:state][:ruby_error_info]
|
91
|
+
|
92
|
+
result[:state][:ruby_error_info] = nil if ruby_error
|
93
|
+
|
65
94
|
if result[:error]
|
66
|
-
|
67
|
-
|
68
|
-
|
95
|
+
if ruby_error
|
96
|
+
raise SweetMoon::Errors::SweetMoonErrorHelper.merge_traceback!(
|
97
|
+
ruby_error, result[:error][:value]
|
98
|
+
)
|
99
|
+
else
|
100
|
+
raise SweetMoon::Errors::SweetMoonErrorHelper.for(
|
101
|
+
result[:error][:status]
|
102
|
+
), result[:error][:value]
|
103
|
+
end
|
69
104
|
end
|
70
105
|
|
71
106
|
result
|
data/dsl/errors.rb
CHANGED
@@ -10,6 +10,14 @@ module SweetMoon
|
|
10
10
|
class LuaFileError < LuaError; end
|
11
11
|
|
12
12
|
module SweetMoonErrorHelper
|
13
|
+
def merge_traceback!(ruby_error, lua_traceback)
|
14
|
+
ruby_error.set_backtrace(
|
15
|
+
ruby_error.backtrace.concat(lua_traceback.split("\n"))
|
16
|
+
)
|
17
|
+
|
18
|
+
ruby_error
|
19
|
+
end
|
20
|
+
|
13
21
|
def for(status)
|
14
22
|
case status
|
15
23
|
when :runtime then LuaRuntimeError
|
@@ -22,7 +30,7 @@ module SweetMoon
|
|
22
30
|
end
|
23
31
|
end
|
24
32
|
|
25
|
-
module_function :for
|
33
|
+
module_function :for, :merge_traceback!
|
26
34
|
end
|
27
35
|
end
|
28
36
|
end
|
data/dsl/fennel.rb
CHANGED
@@ -11,6 +11,8 @@ module DSL
|
|
11
11
|
'table.insert(package.loaders or package.searchers, fennel.searcher)'
|
12
12
|
)
|
13
13
|
|
14
|
+
@state.eval('debug.traceback = fennel.traceback')
|
15
|
+
|
14
16
|
@eval = @state.get(:fennel, :eval)
|
15
17
|
@dofile = @state.get(:fennel, :dofile)
|
16
18
|
@version = @state.get(:fennel, :version)
|
data/dsl/state.rb
CHANGED
@@ -7,7 +7,7 @@ module DSL
|
|
7
7
|
include DSL::Concerns::Packages
|
8
8
|
include DSL::Concerns::Fennel
|
9
9
|
|
10
|
-
attr_reader :meta
|
10
|
+
attr_reader :meta, :api
|
11
11
|
|
12
12
|
def initialize(api_component, interpreter_component, controller, options = {})
|
13
13
|
@api = api_component[:api]
|
@@ -22,6 +22,10 @@ module DSL
|
|
22
22
|
add_package_cpath(options[:package_cpath]) if options[:package_cpath]
|
23
23
|
end
|
24
24
|
|
25
|
+
def raw
|
26
|
+
@state
|
27
|
+
end
|
28
|
+
|
25
29
|
def eval(input, outputs = 1)
|
26
30
|
@controller[:eval!].(@api, @interpreter, state, input, outputs)[:output]
|
27
31
|
end
|
@@ -34,8 +38,10 @@ module DSL
|
|
34
38
|
@controller[:get!].(@api, @interpreter, state, variable, key)[:output]
|
35
39
|
end
|
36
40
|
|
37
|
-
def set(variable, value)
|
38
|
-
@controller[:set!].(
|
41
|
+
def set(variable, key_or_value, value = nil)
|
42
|
+
@controller[:set!].(
|
43
|
+
@api, @interpreter, state, variable, key_or_value, value
|
44
|
+
)[:output]
|
39
45
|
end
|
40
46
|
|
41
47
|
def destroy
|
@@ -6,6 +6,7 @@ module Logic
|
|
6
6
|
LUA_REGISTRYINDEX: -10_000,
|
7
7
|
LUA_GLOBALSINDEX: -10_001,
|
8
8
|
|
9
|
+
# lua_isinteger lua_pushinteger lua_tointeger
|
9
10
|
requires: %i[
|
10
11
|
lua_close lua_gettable lua_gettop lua_insert lua_newtable lua_next lua_open
|
11
12
|
lua_pcall lua_pushboolean lua_pushcclosure lua_pushnil lua_pushnumber
|
@@ -12,11 +12,11 @@ module Logic
|
|
12
12
|
|
13
13
|
# lua_isinteger lua_pushinteger lua_tointeger
|
14
14
|
requires: %i[
|
15
|
-
lua_close lua_createtable lua_getfield
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
15
|
+
lua_close lua_createtable lua_getfield lua_gettop lua_next lua_pcall
|
16
|
+
lua_pushboolean lua_pushcclosure lua_pushnil lua_pushnumber lua_pushstring
|
17
|
+
lua_rawgeti lua_settable lua_settop lua_toboolean lua_tonumber lua_topointer
|
18
|
+
lua_tostring lua_type lua_typename luaL_loadfile luaL_loadstring luaL_newstate
|
19
|
+
luaL_openlibs luaL_ref lua_getglobal lua_setglobal
|
20
20
|
],
|
21
21
|
|
22
22
|
status: {
|
data/logic/spec.rb
CHANGED
@@ -2,7 +2,7 @@ module Logic
|
|
2
2
|
Spec = {
|
3
3
|
name: 'sweet-moon',
|
4
4
|
command: 'sweet-moon',
|
5
|
-
version: '0.0.
|
5
|
+
version: '0.0.5',
|
6
6
|
author: 'gbaptista',
|
7
7
|
summary: 'Lua / Fennel from Ruby and vice versa. Support to LuaJIT, Lua 5.0, ' \
|
8
8
|
'and 5.1. Lua C API for Lua 5, 4, and 3. LuaRocks and fnx integration.',
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sweet-moon
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- gbaptista
|
8
8
|
autorequire:
|
9
9
|
bindir: ports/in/shell
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-03-
|
11
|
+
date: 2022-03-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ffi
|