Dirty-howto play with plugins (was Re: Integer comparison)

goran.krampe at bluefish.se goran.krampe at bluefish.se
Thu Feb 19 13:15:14 UTC 2004


Juergen Bullinger <juergen.bullinger at gmx.net> wrote:
[SNIP]
> I am thinking abotu implementing an Interface to GMP (Linux), could you give me some advice about where to search for documentation on how to do that?

Well, here is a short summary with some good keywords for you to search
on:

To interface with external libraries you either use FFI
(http://minnow.cc.gatech.edu/squeak/1414) or build a plugin. For this I
am pretty sure you want a plugin since the overhead for each call in FFI
is high and I assume you want to be able to call "often".

A plugin is built something like this:

1. Write the BlablaPlugin class (check for samples in Squeak, base your
code on the ones that subclass from SmartSyntaxInterpreterPlugin). This
class represents the plugin and the methods in itis written in "slang" -
a subset of Smalltalk that is autotranslatable to C.

2. Learn how to use VMMaker. VMMaker produces the C-source for the VM
and for all the plugins. Bring it up and let it generate your source
onto disk into the source tree of the Squeak VM (that you have obtained
elsewhere). You can get VMMaker to only regenerate the plugin. You also
select using dragndrop to either generate an internal or external
plugin. External is nice when developing since it can be
loaded/unloaded, see below.

3. Build the VM using the tools for your OS, (make). If you had VMMaker
to generate your plugin as an external it should have produced some
C-code in a suitable place in the src-tree and make should have built a
shared library for it.

4. From Squeak - write a method that references the primitive and try to
call it. If all goes well it will autoload the plugin and run the
primitive. You can see your loaded plugins using:

	Smalltalk listLoadedModules (print it gives:)

#('B2DPlugin 8 April 2003 (i)' 'SocketPlugin 8 April 2003 (i)'
'LargeIntegers v1.2 8 April 2003 (i)' 'BitBltPlugin 8 April 2003 (i)'
'SecurityPlugin 8 April 2003 (i)' 'FilePlugin 8 April 2003 (i)'
'MiscPrimitivePlugin 8 April 2003 (i)')

...and unload one using say:

	Smalltalk unloadModule: 'GtkPlugin'

It will be loaded again on demand.

Here is a silly example of a plugin primitive, itwill simply answer the
size of a String sent in as an argument:


GtkPlugin>>primitiveTest: aString
	| sz |
	self primitive: 'primitiveTest' parameters: #(String).
	sz _ interpreterProxy slotSizeOf: (aString asOop: String).
	^sz asOop: SmallInteger

...the above method will be autotranslated into C by VMMaker. Now in
another class we can call it like this:

SomeClass>>test: aString
	<primitive: 'primitiveTest' module: 'GtkPlugin'>
	^self primitiveFailed



Well, hopefully this got you started.

Cheers, Göran



More information about the Squeak-dev mailing list