Class: Mlc::Abstract::Snippet
- Inherits:
-
Object
- Object
- Mlc::Abstract::Snippet
- Defined in:
- lib/mlc/abstract/snippet.rb
Instance Method Summary collapse
- #<<(child) ⇒ Object
-
#initialize ⇒ Snippet
constructor
A new instance of Snippet.
- #to_lua(opts = {}) ⇒ Object
Constructor Details
#initialize ⇒ Snippet
Returns a new instance of Snippet.
4 5 6 |
# File 'lib/mlc/abstract/snippet.rb', line 4 def initialize @children = [] end |
Instance Method Details
#<<(child) ⇒ Object
24 25 26 |
# File 'lib/mlc/abstract/snippet.rb', line 24 def <<(child) @children << child end |
#to_lua(opts = {}) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/mlc/abstract/snippet.rb', line 8 def to_lua(opts = {}) template = <<URMOM (function (mlc) local _scope, _global, _const, _ = mlc.scope, mlc.global, mlc.const, mlc.helpers LVARS STUFF end)(Mlc) URMOM state = Mlc::ParserState.new (opts[:require] ? "local Mlc = require('mlc')\n" : '') + template.gsub('STUFF', @children.first.to_lua(1, opts, state)). gsub('LVARS', state.lvars.empty? ? '' : "\n #{state.lvars_define}") end |