Help design a plugin system for a DSL

Discussion in 'Ruby' started by Chris Lowis, Aug 29, 2007.

  1. Chris Lowis

    Chris Lowis Guest


    I've been working through the "Creating DSLs with Ruby" tutorial here :

    In my DSL I'd like users to be able to write code such as this :

    myDSL do
    plugin "extra_functions"


    that is, to extend the range of callable functions using a kind of
    "plugin" system.

    The code that I have to implement this so far looks like :

    class myDSL
    def initialize(name)
    @name = name

    def self.load(name)
    dsl = new(name)
    dsl = dsl.instance_eval(

    def myDSL

    def plugin(file)
    puts "loading plugin: #{file}"
    require "./plugins/#{file}.rb"

    def basic_function()
    # a "core" method of the DSL.

    which is called using a short loader file like this :

    require 'myDSL'
    name = ARGV.shift
    name = myDSL.load(name)

    In the extra_functions.rb "plugin" I have a method definition

    def a_special_function
    # does something special

    I'm concerned that this is poor design, as the plugin functions will not
    be very well encapsulated. Requiring two plugins that define the same
    method names will cause the wrong methods to be called from the DSL.

    What is a sensible way to solve this problem ? My thought is to use
    method_missing to traverse plugin Classes in the order they were loaded,
    looking for the function called. Is this a good way to proceed ? Any
    other suggestions ?

    Chris Lowis, Aug 29, 2007
    1. Advertisements

  2. Chris Lowis

    Mark T Guest

    With a dynamic language as flexible as Ruby, using a 'plug-in'
    metaphor/technique/description feels to me like the 4GL languages of
    ten.ish years ago.

    I cannot claim to understand everything.
    Though here the writing between the lines was that understanding is optional.

    Plug-ins are great for Firefox. Where the end-user is the end-user.

    <goes back to sleep/>
    Mark T, Aug 29, 2007
    1. Advertisements

  3. Chris Lowis

    Chris Lowis Guest

    Though here the writing between the lines was that understanding is
    Thank you for your comments. Apologies if my explanation was unclear.
    The end result I'd like is to allow the user to issue a command in the
    DSL that unlocks for them additional commands to use in the DSL.

    To give a concrete example, this is an idea for a hardware automation
    system (for automating experiments). The user can type "plugin
    Acquisition System A" and access a series of commands for controlling
    acquisition system A. There may be other "plugins" for stepper motors
    for example.

    Apologies if the terminology "plugin" is antiquated, or wrong - I was
    trying to choose a term that my users (and I!) can grasp!

    Would appreciate any more thoughts on the best way to achieve this,

    Chris Lowis, Aug 29, 2007
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.