Class: Lignite::DirectCommands
- Inherits:
-
Object
- Object
- Lignite::DirectCommands
- Includes:
- VariableDeclarer
- Defined in:
- lib/lignite/direct_commands.rb
Instance Method Summary collapse
- #block(&body) ⇒ Object
-
#initialize(conn = Connection.create) ⇒ DirectCommands
constructor
A new instance of DirectCommands.
- #method_missing(name, *args) ⇒ Object
- #variables ⇒ Object
- #with_reply(&body) ⇒ Object
Methods included from VariableDeclarer
#array8, #data16, #data32, #data8, #dataf, #datas
Constructor Details
#initialize(conn = Connection.create) ⇒ DirectCommands
Returns a new instance of DirectCommands.
4 5 6 7 8 |
# File 'lib/lignite/direct_commands.rb', line 4 def initialize(conn = Connection.create) @op_compiler = OpCompiler.new @sender = MessageSender.new(conn) @globals = nil end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args) ⇒ Object
37 38 39 40 41 42 43 44 |
# File 'lib/lignite/direct_commands.rb', line 37 def method_missing(name, *args) if @op_compiler.respond_to?(name) insb = @op_compiler.send(name, *args) @sender.direct_command(insb) else super end end |
Instance Method Details
#block(&body) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/lignite/direct_commands.rb', line 23 def block(&body) locals = Variables.new bodyc = BodyCompiler.new(@globals, locals) bodyc.instance_exec(&body) bs = bodyc.bytes lsize = locals.bytesize if @globals @sender.direct_command_with_reply(bs, global_size: @globals.bytesize, local_size: lsize) else @sender.direct_command(bs, global_size: 0, local_size: lsize) end end |
#variables ⇒ Object
10 11 12 |
# File 'lib/lignite/direct_commands.rb', line 10 def variables @globals end |