Class: LivecodeServer::Daemon

Inherits:
Object
  • Object
show all
Defined in:
lib/livecode_server/daemon.rb

Overview

LivecodeServer daemon

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(scope = nil) ⇒ Daemon

Returns a new instance of Daemon.



7
8
9
10
# File 'lib/livecode_server/daemon.rb', line 7

def initialize(scope=nil)
  @scope = Scope.new(self)
  @output = ""
end

Instance Attribute Details

#scopeObject (readonly)

Returns the value of attribute scope.



5
6
7
# File 'lib/livecode_server/daemon.rb', line 5

def scope
  @scope
end

Instance Method Details

#output(string, prefix = nil) ⇒ Object



12
13
14
15
16
# File 'lib/livecode_server/daemon.rb', line 12

def output(string, prefix=nil)
  @output += string + "\n"
  puts (prefix) ? "#{prefix} #{string}" : string
  return nil
end

#run(code) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/livecode_server/daemon.rb', line 18

def run(code)
  code = code.strip
  @output = ""
  puts
  begin
    puts "--- #{Time.now}:"
    puts ">> #{code}" 
    result = eval(code, @scope.get_binding)
    puts "=> #{result}" 
  rescue Exception => e
    output "#{e.class}: #{e}", "!!"
  end
  return @output
end