Class: LivecodeServer::Daemon

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(scope = nil) ⇒ Daemon

Returns a new instance of Daemon.



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

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

Instance Attribute Details

#scopeObject (readonly)

Returns the value of attribute scope.



3
4
5
# File 'lib/livecode_server/daemon.rb', line 3

def scope
  @scope
end

Instance Method Details

#output(string, prefix = nil) ⇒ Object



10
11
12
13
14
# File 'lib/livecode_server/daemon.rb', line 10

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

#run(code) ⇒ Object



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

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