class EleetScript::BaseEngine
Public Class Methods
new()
click to toggle source
# File lib/engine/engine.rb, line 19 def initialize raise CannotInstantiateBaseEngine.new end
Public Instance Methods
[](name)
click to toggle source
# File lib/engine/engine.rb, line 47 def [](name) load var, ns = unnest(name) to_ruby_value(ns[var]) end
[]=(name, value, options = {})
click to toggle source
# File lib/engine/engine.rb, line 53 def []=(name, value, options = {}) load var, ns = unnest(name) if var[0] =~ /[A-Z]/ && ns.constants.has_key?(var) memory.root_namespace["Errors"].call("<", [memory.root_namespace["String"].new_with_value("Cannot reassign constant via the Engine.", memory.root_namespace)]) else ns[var] = to_eleet_value(value, options) end end
call(method_name, *args)
click to toggle source
# File lib/engine/engine.rb, line 35 def call(method_name, *args) method_name = method_name.to_s if method_name =~ /\./ raise CannotCallInstanceOrClassMethodsException.new end method_name, ns = unnest(method_name) eleet_args = args.map do |arg| to_eleet_value(arg) end to_ruby_value(ns.current_self.call(method_name, eleet_args)) end
evaluate(code)
click to toggle source
# File lib/engine/engine.rb, line 23 def evaluate(code) begin to_ruby_value(eval(code)) rescue Exception => e false end end
execute(code)
click to toggle source
# File lib/engine/engine.rb, line 31 def execute(code) evaluate(code) end
get(var, raw = false)
click to toggle source
# File lib/engine/engine.rb, line 63 def get(var, raw = false) val = self[var] if raw val.eleet_obj else val end end
memory()
click to toggle source
# File lib/engine/engine.rb, line 76 def memory @memory ||= Memory.new end
set(var, value, options = {})
click to toggle source
# File lib/engine/engine.rb, line 72 def set(var, value, options = {}) send(:[]=, var, value, options) end
Protected Instance Methods
engine_root_ns()
click to toggle source
# File lib/engine/engine.rb, line 102 def engine_root_ns memory.root_namespace end
eval(code)
click to toggle source
# File lib/engine/engine.rb, line 86 def eval(code) interpreter.eval(code) end
interpreter()
click to toggle source
# File lib/engine/engine.rb, line 90 def interpreter @interpreter ||= Interpreter.new(memory) end
load()
click to toggle source
# File lib/engine/engine.rb, line 82 def load interpreter unless @interpreter end
to_eleet_value(value, options = {})
click to toggle source
# File lib/engine/engine.rb, line 94 def to_eleet_value(value, options = {}) Values.to_eleet_value(value, self, options) end
to_ruby_value(value)
click to toggle source
# File lib/engine/engine.rb, line 98 def to_ruby_value(value) Values.to_ruby_value(value, self) end
unnest(name)
click to toggle source
# File lib/engine/engine.rb, line 106 def unnest(name) name = name.to_s if name.start_with?("::") name = name[2..-1] ns = memory.root_namespace else ns = engine_root_ns end nesting = name.split("::") var = nesting.pop nesting.each do |new_ns| ns = ns.namespace(new_ns) end [var, ns] end