Help design a plugin system for a DSL

C

Chris Lowis

Hello,

I've been working through the "Creating DSLs with Ruby" tutorial here :
http://www.artima.com/rubycs/articles/ruby_as_dsl4.html

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

myDSL do
plugin "extra_functions"

a_special_function
basic_function
end

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
end

def self.load(name)
dsl = new(name)
dsl = dsl.instance_eval(File.read(name))
dsl
end

def myDSL
yield
end

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

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

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
end

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
 
M

Mark T

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/>
 
C

Chris Lowis

Though here the writing between the lines was that understanding is
optional.

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
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top