In VisualWorks, when you want to link to an external library, you have to define an ExternalInterface class - it looks a little bit like this:
XML.Tidy defineClass: #TidyCInterface
superclass: #{External.ExternalInterface}
indexedType: #none
private: false
instanceVariableNames: ''
classInstanceVariableNames: ''
imports: '
XML.Tidy.TidyCInterfaceDictionary.*
'
category: 'LibTidy'
attributes: #(
#(#includeFiles #())
#(#includeDirectories #())
#(#libraryFiles #('[win]tidylib.dll' '[unix]tidylib.so' '[mac]libtidy.dylib'))
#(#libraryDirectories #())
#(#beVirtual false)
#(#optimizationLevel #full))
Yes, a big class definition indeed. The libraryFiles part is the most important and also the most tricky - you see, you can define several library file names in there and put funky [] bits in there to define what platform you want the library to work with - but here's the catch, unless you catch a special exception, the library loader will try to load all of those libraries, regardless of what platform you're currently running on. What a mess!
Travis reminded me of this quagmire. The worst part about it is never being able to remember how to fix the exception or the right syntax inside that special class definition message... no more! Pragmas to the rescue, we can now do the following:
<library: 'tidylib.dll' platform: 'win'>
<library: 'tidylib.so' platform: 'unix'>
<library: 'tidylib.dylib' platform: 'mac'>
It will only try to load the library if the platform matches the platform you're on. Like the old [] nonsense, you can still do wild card matching on the platform too, eg:
<library: 'tidylib.dll' platform: 'win*i386'>
You can also specify a library that isn't bound to a platform:
<library: 'tidylib.dll'>
This will assume it can be loaded on all platforms. I doubt this'll get rarely used, but hey, it was easy enough to do. And finally, to sweeten the deal, I put in some common short cuts, so you could in fact write:
<win: 'tidylib.dll'>
<unix: 'tidylib.so'>
<mac: 'tidylib.dylib'>
Simply load up the package External-Interface-Pragmas from Public Store and enjoy! Cheers.