vrobot4/source/module.rb

46 lines
821 B
Ruby

module Vrobot4::Module
class Command
attr_reader :help_str
def initialize fn, help
@function = fn
@help_str = help
end
def run m, argv
@function.call(m, argv)
end
end
class Module
def initialize
@commands = {}
end
def register fn, help
@commands[fn.to_s] = Command.new(self.method(fn), help)
end
def eachCmd
@commands.each {|cmd| yield cmd}
end
def onCommand m, cnam, argv
@commands[cnam].run(m, argv) if @commands.has_key? cnam
end
end
@@module_types = {}
def self.add_module_type t, name
@@module_types[name] = t
Vrobot4.log :INFO, "added module type:", name
end
def self.get_module_type s
@@module_types[s]
end
end
## EOF