Class: ZunScript::ZExternBlock

Inherits:
ZBlock show all
Defined in:
lib/zunscript/block.rb

Instance Method Summary collapse

Constructor Details

#initialize(receiver, method, env, args = []) ⇒ ZExternBlock

Returns a new instance of ZExternBlock.



36
37
38
39
40
41
# File 'lib/zunscript/block.rb', line 36

def initialize receiver, method, env, args = []
  @env = env
  @receiver = receiver
  @method = method
  @args = args
end

Instance Method Details

#bind(args) ⇒ Object



64
65
66
# File 'lib/zunscript/block.rb', line 64

def bind args
  return ZExternBlock.new @receiver, @method, @env, @args + parse_args(args)
end

#call(args) ⇒ Object



54
55
56
57
58
59
60
61
62
# File 'lib/zunscript/block.rb', line 54

def call args
  res = @receiver.send @method, *(@args + parse_args(args))
  case res
  when Fixnum, Float
    return ZNum.new res, @env
  when String
    return ZString.new res, @env
  end
end

#inspectObject



68
69
70
# File 'lib/zunscript/block.rb', line 68

def inspect
  return "#<EXTERN #{@receiver}\##{@method.to_s}>"
end

#parse_args(args) ⇒ Object



43
44
45
46
47
48
49
50
51
52
# File 'lib/zunscript/block.rb', line 43

def parse_args args
  return args.map do |a|
    a = a.get if a.is_a? VariableReference
    if a.is_a? ZNum or a.is_a? ZString or a.is_a? ZBool
      a.value
    else
      a
    end
  end
end