class Script

The Script class defines te characteristic of an executable program.

Attributes

prog[RW]

Public Class Methods

new(name, owner, language) click to toggle source

Create a new Script

name

The filename of the script

owner

The owner id of this script

language

The language of the script

return

A handle to the new Object

# File lib/core/script.rb, line 33
def initialize(name, owner, language)
  super(name, owner)
  self.language = language
  @prog = nil
end

Public Instance Methods

compile() click to toggle source

Compile a program

return

success or failure

# File lib/core/script.rb, line 60
def compile
  case language
  when :boolexp
    true
  when :fart
    @prog = Farts::Parser.new.parse(src)
    log.info "Compile of FART program - #{name}"
    true
  else
    false
  end
rescue Exception
  log.error $!
  @prog = nil
  false
end
execute(ev) click to toggle source

Execute a program

return

success or failure

# File lib/core/script.rb, line 79
def execute(ev)
  case language
  when :boolexp
    actor = get_object(ev.from)
    BoolExpParser.new(actor).parse(src)
  when :fart
    vars = {}
    vars['actor'] = get_object(ev.from)
    vars['this'] = get_object(ev.to)
    if ev.msg.kind_of?(GameObject)
      vars['args'] = get_object(ev.msg)
    else
      vars['args'] = ev.msg
    end
    load if !@prog
    compile if !@prog
    @prog ? @prog.execute(vars) : false
  else
    false
  end
rescue Exception
  log.error $!
  false
end
load(str=nil) click to toggle source

Load a program

return

success or failure

# File lib/core/script.rb, line 41
def load(str=nil)
  case language
  when :boolexp
    self.src = str
    log.info "Load of BoolExp program - #{name}"
    true
  when :fart
    File.open("farts/#{name}.fart") {|f|
      self.src = f.read
    }
    log.info "Load of FART program - #{name}"
    true
  else
    false
  end
end