sweet-moon 0.0.3 → 0.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 +4 -4
- data/.rubocop.yml +3 -0
- data/README.md +283 -16
- data/components/api.rb +6 -3
- data/components/default.rb +17 -0
- 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 -50
- data/components/interpreters/50/interpreter.rb +27 -9
- data/components/interpreters/50/reader.rb +2 -62
- data/components/interpreters/50/table.rb +12 -49
- data/components/interpreters/50/writer.rb +2 -40
- data/components/interpreters/51/function.rb +3 -49
- data/components/interpreters/51/interpreter.rb +16 -10
- data/components/interpreters/51/reader.rb +2 -62
- data/components/interpreters/51/table.rb +2 -56
- data/components/interpreters/51/writer.rb +2 -40
- data/components/interpreters/54/function.rb +80 -24
- data/components/interpreters/54/interpreter.rb +17 -9
- data/components/interpreters/54/reader.rb +11 -10
- data/components/interpreters/54/table.rb +17 -12
- data/components/interpreters/54/writer.rb +4 -4
- data/config/tests.sample.yml +10 -7
- data/controllers/api.rb +4 -1
- data/controllers/state.rb +47 -12
- data/dsl/api.rb +23 -3
- data/dsl/cache.rb +90 -76
- data/dsl/errors.rb +9 -1
- data/dsl/fennel.rb +2 -0
- data/dsl/global.rb +26 -27
- data/dsl/state.rb +26 -7
- data/dsl/sweet_moon.rb +4 -4
- data/logic/interpreters/interpreter_50.rb +1 -0
- data/logic/interpreters/interpreter_54.rb +5 -5
- data/logic/spec.rb +1 -1
- metadata +3 -2
data/dsl/cache.rb
CHANGED
@@ -7,112 +7,126 @@ require_relative '../controllers/state'
|
|
7
7
|
require_relative 'api'
|
8
8
|
require_relative 'sweet_moon'
|
9
9
|
|
10
|
-
|
11
|
-
|
10
|
+
module DSL
|
11
|
+
class Cache
|
12
|
+
include Singleton
|
12
13
|
|
13
|
-
|
14
|
-
|
14
|
+
API_KEYS = %i[shared_objects api_reference global_ffi]
|
15
|
+
STATE_KEYS = %i[interpreter package_path package_cpath]
|
15
16
|
|
16
|
-
|
17
|
-
|
17
|
+
def api_keys?(options)
|
18
|
+
API_KEYS.each { |key| return true if options.key?(key) }
|
19
|
+
false
|
20
|
+
end
|
18
21
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
+
def state_keys?(options)
|
23
|
+
STATE_KEYS.each { |key| return true if options.key?(key) }
|
24
|
+
false
|
25
|
+
end
|
22
26
|
|
23
|
-
|
24
|
-
|
25
|
-
end
|
27
|
+
def clear_global!
|
28
|
+
@cache[:global_state]&._unsafely_destroy
|
26
29
|
|
27
|
-
|
28
|
-
|
30
|
+
@cache.each_key { |key| @cache.delete(key) if key[/^global/] }
|
31
|
+
end
|
29
32
|
|
30
|
-
|
33
|
+
def keys
|
34
|
+
@cache.keys
|
35
|
+
end
|
31
36
|
|
32
|
-
|
37
|
+
def initialize
|
38
|
+
@cache = {}
|
39
|
+
end
|
33
40
|
|
34
|
-
|
35
|
-
|
36
|
-
api, options, :global_interpreter_module
|
37
|
-
)
|
41
|
+
def global_state(options = {}, recreate: false)
|
42
|
+
key = :global_state
|
38
43
|
|
39
|
-
|
40
|
-
@cache[key].instance_eval('undef :destroy', __FILE__, __LINE__)
|
44
|
+
clear_global_state_cache!(options) if recreate
|
41
45
|
|
42
|
-
|
43
|
-
end
|
46
|
+
return @cache[key] if @cache[key]
|
44
47
|
|
45
|
-
|
46
|
-
|
48
|
+
api = Cache.instance.api_module(options, :global_api_module)
|
49
|
+
interpreter = Cache.instance.interpreter_module(
|
50
|
+
api, options, :global_interpreter_module
|
51
|
+
)
|
47
52
|
|
48
|
-
|
53
|
+
@cache[key] = DSL::State.new(api, interpreter, Controller::State, options)
|
54
|
+
@cache[key].instance_eval('undef :destroy', __FILE__, __LINE__)
|
49
55
|
|
50
|
-
|
51
|
-
|
56
|
+
@cache[key]
|
57
|
+
end
|
52
58
|
|
53
|
-
|
54
|
-
|
55
|
-
@cache[key] ||= DSL::Api.new(api_module(options, api_module_key))
|
56
|
-
end
|
59
|
+
def global_api(options = {}, recreate: false)
|
60
|
+
key = :global_api
|
57
61
|
|
58
|
-
|
59
|
-
key ||= cache_key_for(:api_module, options, %i[shared_objects api_reference])
|
60
|
-
@cache[key] ||= Controller::API[:handle!].(options)
|
61
|
-
end
|
62
|
+
clear_global_api_cache! if recreate
|
62
63
|
|
63
|
-
|
64
|
-
|
65
|
-
:interpreter_module,
|
66
|
-
{ shared_objects: api[:meta][:elected][:shared_objects],
|
67
|
-
api_reference: api[:meta][:elected][:api_reference],
|
68
|
-
interpreter: options[:interpreter], package_path: options[:package_path],
|
69
|
-
package_cpath: options[:package_cpath] },
|
70
|
-
%i[shared_objects api_reference interpreter package_path package_cpath]
|
71
|
-
)
|
72
|
-
|
73
|
-
@cache[key] ||= Controller::Interpreter[:handle!].(api, options)
|
74
|
-
end
|
64
|
+
@cache[key] ||= api(options, :global_api, :global_api_module)
|
65
|
+
end
|
75
66
|
|
76
|
-
|
67
|
+
def api(options = {}, key = nil, api_module_key = nil)
|
68
|
+
key ||= cache_key_for(:api, options, API_KEYS)
|
69
|
+
@cache[key] ||= DSL::Api.new(api_module(options, api_module_key))
|
70
|
+
end
|
77
71
|
|
78
|
-
|
79
|
-
|
72
|
+
def api_module(options = {}, key = nil)
|
73
|
+
key ||= cache_key_for(:api_module, options, API_KEYS)
|
74
|
+
@cache[key] ||= Controller::API[:handle!].(options)
|
75
|
+
end
|
80
76
|
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
77
|
+
def interpreter_module(api, options = {}, key = nil)
|
78
|
+
key ||= cache_key_for(
|
79
|
+
:interpreter_module,
|
80
|
+
{ shared_objects: api[:meta][:elected][:shared_objects],
|
81
|
+
api_reference: api[:meta][:elected][:api_reference],
|
82
|
+
global_ffi: api[:meta][:global_ffi],
|
83
|
+
interpreter: options[:interpreter], package_path: options[:package_path],
|
84
|
+
package_cpath: options[:package_cpath] },
|
85
|
+
API_KEYS.concat(STATE_KEYS)
|
86
|
+
)
|
87
|
+
|
88
|
+
@cache[key] ||= Controller::Interpreter[:handle!].(api, options)
|
85
89
|
end
|
86
|
-
end
|
87
90
|
|
88
|
-
|
89
|
-
|
91
|
+
def cache_key_for(prefix, options = {}, relevant_keys = [])
|
92
|
+
values = [prefix]
|
90
93
|
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
+
relevant_keys.each do |key|
|
95
|
+
value = options[key]
|
96
|
+
value = options[key.to_s] if value.nil?
|
94
97
|
|
95
|
-
|
98
|
+
values << (value.is_a?(Array) ? value.sort.join(':') : value.inspect)
|
99
|
+
end
|
96
100
|
|
97
|
-
|
98
|
-
@cache.delete(key)
|
101
|
+
values.join('|')
|
99
102
|
end
|
100
103
|
|
101
|
-
|
102
|
-
end
|
104
|
+
private
|
103
105
|
|
104
|
-
|
105
|
-
|
106
|
+
def clear_global_api_cache!
|
107
|
+
@cache[:global_state]&._unsafely_destroy
|
106
108
|
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
elsif value
|
112
|
-
values << value
|
109
|
+
%i[global_api global_api_module
|
110
|
+
global_interpreter_module
|
111
|
+
global_state].each do |key|
|
112
|
+
@cache.delete(key)
|
113
113
|
end
|
114
114
|
end
|
115
115
|
|
116
|
-
|
116
|
+
def clear_global_state_cache!(options)
|
117
|
+
@cache[:global_state]&._unsafely_destroy
|
118
|
+
|
119
|
+
%i[global_interpreter_module global_state].each do |key|
|
120
|
+
@cache.delete(key)
|
121
|
+
end
|
122
|
+
|
123
|
+
return unless api_keys?(options)
|
124
|
+
|
125
|
+
%i[global_api global_api_module].each do |key|
|
126
|
+
@cache.delete(key)
|
127
|
+
end
|
128
|
+
|
129
|
+
global_api(options, recreate: true)
|
130
|
+
end
|
117
131
|
end
|
118
132
|
end
|
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/global.rb
CHANGED
@@ -2,41 +2,40 @@ require_relative '../logic/options'
|
|
2
2
|
|
3
3
|
require_relative 'cache'
|
4
4
|
|
5
|
-
module
|
6
|
-
|
7
|
-
|
8
|
-
|
5
|
+
module DSL
|
6
|
+
module Global
|
7
|
+
def api
|
8
|
+
Cache.instance.global_api
|
9
|
+
end
|
9
10
|
|
10
|
-
|
11
|
-
|
12
|
-
|
11
|
+
def state
|
12
|
+
Cache.instance.global_state
|
13
|
+
end
|
13
14
|
|
14
|
-
|
15
|
-
|
15
|
+
def config(options = {})
|
16
|
+
options = Logic::Options[:normalize].(options)
|
16
17
|
|
17
|
-
|
18
|
-
|
19
|
-
|
18
|
+
if Cache.instance.api_keys?(options)
|
19
|
+
Cache.instance.global_api(options, recreate: true)
|
20
|
+
end
|
20
21
|
|
21
|
-
|
22
|
-
options.key?(:interpreter) ||
|
23
|
-
options.key?(:package_path) ||
|
24
|
-
options.key?(:package_cpath)
|
22
|
+
return unless Cache.instance.state_keys?(options)
|
25
23
|
|
26
|
-
|
24
|
+
Cache.instance.global_state(options, recreate: true)
|
27
25
|
|
28
|
-
|
29
|
-
|
26
|
+
nil
|
27
|
+
end
|
30
28
|
|
31
|
-
|
32
|
-
|
29
|
+
def cached(all: false)
|
30
|
+
return Cache.instance.keys if all
|
33
31
|
|
34
|
-
|
35
|
-
|
32
|
+
Cache.instance.keys.select { |key| key[/^global/] }
|
33
|
+
end
|
36
34
|
|
37
|
-
|
38
|
-
|
39
|
-
|
35
|
+
def clear
|
36
|
+
Cache.instance.clear_global!
|
37
|
+
end
|
40
38
|
|
41
|
-
|
39
|
+
module_function :api, :state, :config, :cached, :clear
|
40
|
+
end
|
42
41
|
end
|
data/dsl/state.rb
CHANGED
@@ -1,13 +1,14 @@
|
|
1
1
|
require_relative 'errors'
|
2
2
|
require_relative 'concerns/packages'
|
3
3
|
require_relative 'concerns/fennel'
|
4
|
+
require_relative '../components/default'
|
4
5
|
|
5
6
|
module DSL
|
6
7
|
class State
|
7
8
|
include DSL::Concerns::Packages
|
8
9
|
include DSL::Concerns::Fennel
|
9
10
|
|
10
|
-
attr_reader :meta
|
11
|
+
attr_reader :meta, :api
|
11
12
|
|
12
13
|
def initialize(api_component, interpreter_component, controller, options = {})
|
13
14
|
@api = api_component[:api]
|
@@ -22,6 +23,10 @@ module DSL
|
|
22
23
|
add_package_cpath(options[:package_cpath]) if options[:package_cpath]
|
23
24
|
end
|
24
25
|
|
26
|
+
def raw
|
27
|
+
@state
|
28
|
+
end
|
29
|
+
|
25
30
|
def eval(input, outputs = 1)
|
26
31
|
@controller[:eval!].(@api, @interpreter, state, input, outputs)[:output]
|
27
32
|
end
|
@@ -34,8 +39,10 @@ module DSL
|
|
34
39
|
@controller[:get!].(@api, @interpreter, state, variable, key)[:output]
|
35
40
|
end
|
36
41
|
|
37
|
-
def set(variable, value)
|
38
|
-
@controller[:set!].(
|
42
|
+
def set(variable, key_or_value, value = nil)
|
43
|
+
@controller[:set!].(
|
44
|
+
@api, @interpreter, state, variable, key_or_value, value
|
45
|
+
)[:output]
|
39
46
|
end
|
40
47
|
|
41
48
|
def destroy
|
@@ -81,13 +88,25 @@ module DSL
|
|
81
88
|
|
82
89
|
private
|
83
90
|
|
84
|
-
def
|
85
|
-
|
91
|
+
def build_api_meta(api_component)
|
92
|
+
global_ffi = Component::Default.instance.options[:global_ffi]
|
93
|
+
|
94
|
+
unless api_component[:meta][:options][:global_ffi].nil?
|
95
|
+
global_ffi = api_component[:meta][:options][:global_ffi]
|
96
|
+
end
|
97
|
+
|
98
|
+
{
|
86
99
|
api_reference: api_component[:meta][:elected][:api_reference],
|
87
100
|
shared_objects: api_component[:meta][:elected][:shared_objects],
|
88
|
-
|
89
|
-
runtime: interpreter_component[:meta][:runtime][:lua]
|
101
|
+
global_ffi: global_ffi
|
90
102
|
}
|
103
|
+
end
|
104
|
+
|
105
|
+
def build_meta(api_component, interpreter_component)
|
106
|
+
meta_data = build_api_meta(api_component)
|
107
|
+
|
108
|
+
meta_data[:interpreter] = interpreter_component[:meta][:elected][:interpreter]
|
109
|
+
meta_data[:runtime] = interpreter_component[:meta][:runtime][:lua]
|
91
110
|
|
92
111
|
@meta = Struct.new(*meta_data.keys).new(*meta_data.values)
|
93
112
|
end
|
data/dsl/sweet_moon.rb
CHANGED
@@ -11,7 +11,7 @@ require_relative '../logic/interpreter'
|
|
11
11
|
module SweetMoon
|
12
12
|
module API
|
13
13
|
def new(options = {})
|
14
|
-
Cache.instance.api(Logic::Options[:normalize].(options))
|
14
|
+
DSL::Cache.instance.api(Logic::Options[:normalize].(options))
|
15
15
|
end
|
16
16
|
|
17
17
|
module_function :new
|
@@ -21,9 +21,9 @@ module SweetMoon
|
|
21
21
|
def new(options = {})
|
22
22
|
options = Logic::Options[:normalize].(options)
|
23
23
|
|
24
|
-
api = Cache.instance.api_module(options)
|
24
|
+
api = DSL::Cache.instance.api_module(options)
|
25
25
|
|
26
|
-
interpreter = Cache.instance.interpreter_module(api, options)
|
26
|
+
interpreter = DSL::Cache.instance.interpreter_module(api, options)
|
27
27
|
|
28
28
|
DSL::State.new(api, interpreter, Controller::State, options)
|
29
29
|
end
|
@@ -46,7 +46,7 @@ module SweetMoon
|
|
46
46
|
end
|
47
47
|
|
48
48
|
def global
|
49
|
-
Global
|
49
|
+
DSL::Global
|
50
50
|
end
|
51
51
|
|
52
52
|
module_function :meta, :global
|
@@ -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.6',
|
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.6
|
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-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ffi
|
@@ -48,6 +48,7 @@ files:
|
|
48
48
|
- LICENSE
|
49
49
|
- README.md
|
50
50
|
- components/api.rb
|
51
|
+
- components/default.rb
|
51
52
|
- components/injections.rb
|
52
53
|
- components/injections/injections_503.rb
|
53
54
|
- components/injections/injections_514.rb
|