The Artima Developer Community
Sponsored Link

Agile Buzz Forum
The way we link to library files in VW... yeesh

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
James Robertson

Posts: 29924
Nickname: jarober61
Registered: Jun, 2003

David Buck, Smalltalker at large
The way we link to library files in VW... yeesh Posted: Jan 8, 2007 5:29 AM
Reply to this message Reply

This post originated from an RSS feed registered with Agile Buzz by James Robertson.
Original Post: The way we link to library files in VW... yeesh
Feed Title: Michael Lucas-Smith
Feed URL: http://www.michaellucassmith.com/site.atom
Feed Description: Smalltalk and my misinterpretations of life
Latest Agile Buzz Posts
Latest Agile Buzz Posts by James Robertson
Latest Posts From Michael Lucas-Smith

Advertisement

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. 

Read: The way we link to library files in VW... yeesh

Topic: Those that Tend the Store need Dialogue Previous Topic   Next Topic Topic: ExpressionBuilder

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use