links to this page:    
View this PageEdit this PageUploads to this PageHistory of this PageTop of the SwikiRecent ChangesSearch the SwikiHelp Guide
Plugin Tutorial for Windows
Last updated at 6:03 pm UTC on 29 April 2009
I wanted to write a page on how to create a plugin, a step by step guide, as it took me some time before I create a plugin for Windows. This is a tutorial to write a plugin that implements float.

Part I: Get these files

There are three zip files needed:
  1. Squeak VM source release http://www.squeakvm.org/win32/release/SqueakVM-Win32-3.10.7-src.zip
  2. Tools for VM compilation http://www.squeakvm.org/win32/release/Squeak-Win32-Tools-1.2.zip
  3. Sqeauk 3.10 executable and image http://ftp.squeak.org/3.10/win/Squeak3.10.2-7179-win32.zip

Part II: Writing the plugin

Now we are ready to write the plugin.
  1. On the Browser create a new category: 'FooFloat'. Create the plugin as subclass of InterpreterPlugin
    InterpreterPlugin subclass: #FooFloatPlugin
    instanceVariableNames: ''
    classVariableNames: ''
    poolDictionaries: ''
    category: 'FooFloat'
  2. We will write two primitives, one to answer identity of a float, the other to answer sum of two floats. Both primitives are of the class FooFloatPlugin.
    primsIdentityOfFloat": aFloat"
    "primitive, return the identity of a float"
    | aFloat |
    self export: true.
    self inline: false.
    self var: aFloat type:' float'.
    aFloat := interpreterProxy stackFloatValue: 0.
    interpreterProxy pop:2.
    interpreterProxy push: (interpreterProxy floatObjectOf: aFloat)
  3. Primitive to answer sum of two floats.
    primsSumOfFloatAnd": float1 :float2"
    "primitive, return the identity of a float"
    | float1 float2 |
    self export: true.
    self inline: false.
    self var: float1 type:' float'.
    self var: float2 type:' float '.
    float2 := interpreterProxy stackFloatValue: 0.
    float1 := interpreterProxy stackFloatValue: 1.
    interpreterProxy pop:3.
    interpreterProxy push: (interpreterProxy floatObjectOf: (float1 + float2))
  4. Add an interface for the plugin by creating a class named 'FooFloat'.
    Object subclass: #FooFloat
    instanceVariableNames: ''
    classVariableNames: ''
    poolDictionaries: ''
    category: 'FooFloat'
  5. We will write two methods to call the two primitives, in class FooFloat. Firstly identityOfFloat:
    identityOfFloat: aFloat
    "return identity of a float"
    < primitive: 'primsIdentityOfFloat' module: 'FooFloatPlugin'>
    ^ FooFloatPlugin doPrimitive: 'primsIdentityOfFloat'
    Note: first statement call the primitive, second statement will execute when primitive fail, or if primitive not found.
  6. Secondly, sumOfFloat: and:
    sumOfFloat:float1 and: float2
    "return sum of two floats"
    < primitive: 'primsSumOfFloatAnd' module: 'FooFloatPlugin'>
    ^ FooFloatPlugin doPrimitive: 'primsSumOfFloatAnd'
  7. Write a class-side method for the plugin.
    ^ 'FooFloatPlugin'
  8. Drag a workspace from the Tools flab. We can now test the primitive. Type the following in the workspace.
    FooFloat new identityOfFloat: 12.34567
    FooFloat new sumOfFloat: 12.34567 and: 13.45678
    ctrl + p at the end of each like you will get the answers which is 12.34567 and 25.80245. Note that at this point primitive will fail, as we haven't generate the plugin, answer are returned by simulator.

Part III: Generating the plugin

  1. Now where we satisfy with the codes, we will compile it into plugin. This tutorial will be explaining on external plugin. In workspace, type this
    VMMakerTool openInWorld
    ctrl + d to open the VMMaker GUI. Fill in the text fields with the following:
    Interpreter class name: Interpreter
    Path to platform code: C:\SqueakVM-Win32-3.10.7\platforms
    Platform name: Win32
    Path to generate sources: C:\SqueakVM-Win32-3.10.7\platforms\win32\build\src
  2. Right click in the Plugins not built pane and select make all internal. From Internal Plugins pane, drag FooFloatPlugin to External Plugins pane. Then, click on Entire to genarate source code for compilation.
  3. From command prompt, cd into C:\SqueakVM-Win32-3.10.7\platforms\win32\build. Then, invoke "make". If there is any error, then click on Entire again in the VMMaker GUI, follow by reinvoke make in the command prompt.
  4. Go to C:\SqueakVM-Win32-3.10.7\platforms\win32\build\obj\vm, find FooFloatPlugin.dll. This is the external plugin that we can use with any Squeak executable. Copy FooFloatPlugin.dll and place it in C:\Squeak3.10.1-7175. Save and quit current Squeak.exe.

A plugin I wrote to perform Gaussian elimination on matrix. MatrixPlugin (Gaussian elimination)