sweet-moon 0.0.4 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
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,12 +23,24 @@ 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
- @controller[:eval!].(@api, @interpreter, state, input, outputs)[:output]
31
+ options = _build_options(outputs, nil)
32
+
33
+ @controller[:eval!].(
34
+ @api, @interpreter, state, input, options[:outputs]
35
+ )[:output]
27
36
  end
28
37
 
29
38
  def load(path, outputs = 1)
30
- @controller[:load!].(@api, @interpreter, state, path, outputs)[:output]
39
+ options = _build_options(outputs, nil)
40
+
41
+ @controller[:load!].(
42
+ @api, @interpreter, state, path, options[:outputs]
43
+ )[:output]
31
44
  end
32
45
 
33
46
  def get(variable, key = nil)
@@ -51,6 +64,22 @@ module DSL
51
64
  nil
52
65
  end
53
66
 
67
+ def _build_options(first, second)
68
+ options = { outputs: 1 }
69
+
70
+ options = options.merge(first) if first.is_a? Hash
71
+ options = options.merge(second) if second.is_a? Hash
72
+
73
+ options[:outputs] = first if first.is_a? Numeric
74
+ options[:outputs] = second if second.is_a? Numeric
75
+
76
+ outputs = options[:outputs] if options[:outputs]
77
+
78
+ options.delete(:outputs)
79
+
80
+ { options: options, outputs: outputs }
81
+ end
82
+
54
83
  def _ensure_min_version!(purpose, lua, jit = nil)
55
84
  version = lua
56
85
  version = jit if meta.interpreter[/jit/] && jit
@@ -83,21 +112,32 @@ module DSL
83
112
 
84
113
  private
85
114
 
86
- def build_meta(api_component, interpreter_component)
87
- meta_data = {
115
+ def build_api_meta(api_component)
116
+ global_ffi = Component::Default.instance.options[:global_ffi]
117
+
118
+ unless api_component[:meta][:options][:global_ffi].nil?
119
+ global_ffi = api_component[:meta][:options][:global_ffi]
120
+ end
121
+
122
+ {
88
123
  api_reference: api_component[:meta][:elected][:api_reference],
89
124
  shared_objects: api_component[:meta][:elected][:shared_objects],
90
- interpreter: interpreter_component[:meta][:elected][:interpreter],
91
- runtime: interpreter_component[:meta][:runtime][:lua]
125
+ global_ffi: global_ffi
92
126
  }
127
+ end
128
+
129
+ def build_meta(api_component, interpreter_component)
130
+ meta_data = build_api_meta(api_component)
131
+
132
+ meta_data[:interpreter] = interpreter_component[:meta][:elected][:interpreter]
133
+ meta_data[:runtime] = interpreter_component[:meta][:runtime][:lua]
93
134
 
94
135
  @meta = Struct.new(*meta_data.keys).new(*meta_data.values)
95
136
  end
96
137
 
97
138
  def state
98
139
  unless @state
99
- raise SweetMoon::Errors::SweetMoonError,
100
- 'The state no longer exists.'
140
+ raise SweetMoon::Errors::SweetMoonError, 'The state no longer exists.'
101
141
  end
102
142
 
103
143
  @state
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
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.4',
5
+ version: '0.0.7',
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
4
+ version: 0.0.7
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-24 00:00:00.000000000 Z
11
+ date: 2022-03-28 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