pluginmgr

The Tcllib contains a package to safely manage plugins to applications called plugin.

You can find the documentation at:


Anyone care to post a simple example? --- jnc 2007-09-19

AK same day - The page::pluginmgr in the page module of Tcllib uses the pluginmgr.


Ok, with the help of AK I was able to get a simple example together... The example is nothing more than a Hello World, with a twist... We can say hello/goodbye in multiple manners. The two plugins I created are Simple and Slang.

1. Create two plugins: You can place plugins in multiple locations, but for my example I made a directory ~/.example/plugin ... That is where I placed the plugin code.

~/.example/plugin/simple.tcl

  proc hello {name} {
    return "Hello $name."
  }

  proc goodbye {name} {
      return "Goodbye $name."
  }

  package provide example::plugin::simple 0.1

~/.example/plugin/slang.tcl

  proc hello {name} {
      return "What's up $name?"
  }

  proc goodbye {name} {
      return "Well, $name. See ya later!"
  }

  package provide example::plugin::slang 0.1

~/.example/plugin/pkgIndex.tcl

  package ifneeded example::plugin::simple 0.1 [list source [file join $dir simple.tcl]]
  package ifneeded example::plugin::slang  0.1 [list source [file join $dir slang.tcl]]

2. Create our program to use the plugins. This you can place anywhere, I always keep a directory for learning, ~/develop/learning/example.tcl is my file.

  package require pluginmgr

  set plugApi { hello goodbye }

  pluginmgr plug -pattern example::plugin::* -api $plugApi
  pluginmgr::paths plug example

  plug load simple
  puts "Simple: [plug do hello John]"
  puts "Simple: [plug do goodbye John]"

  plug load slang
  puts "Slang:  [plug do hello John]"
  puts "Slang:  [plug do goodbye John]"

3. Now run your code!.

  $ tclsh example.tcl
  Simple: Hello John.
  Simple: Goodbye John.
  Slang:  What's Up John?
  Slang:  Well, John, see ya later!

--- jnc 2007-09-19