Building a plugin (Windows)

aldel at alum.mit.edu aldel at alum.mit.edu
Mon Aug 7 20:46:16 UTC 2000


I'm trying to build a simple external plugin, just to see if I can do
it.  As far as I can tell, I followed all the instructions available
(both in http://coweb.cc.gatech.edu/squeakbook/20 and
http://minnow.cc.gatech.edu/squeak/1448), but the primitive I defined
fails when I call it.  I'm working under Windows 98 (for now).

To begin with, is there any way to find out why a primitive failed?
So far I don't know whether it failed to find my DLL, one of the
initialization functions failed or wasn't present, or something went
wrong in the primitive function.  I tried to call Smalltalk
listLoadedModules to find out if the plugin had at least been loaded,
but that calls a primitive which also fails.

Here's what I did:

I wrote a C file, adder.c, using the output of InterpreterPlugin
translate as a framework.  I changed the moduleName and added a
function called primAdd which I believe should add the two parameters
passed with the message and return the result.  (Question: does the
C primitive function's return value matter?  None of the docs I've
seen say whether it means anything.)  I've included the whole adder.c
file below.

I ran InterpreterSupportCode writePluginSupportFiles to generate the
header files needed.  Compiling seemed to require two other header
files, sqWin32.h and sqWin32Alloc.h, which I couldn't figure out how
to generate; so I made empty files with those names and compiled
without further errors.  I built a file called Adder.dll, using a .DEF
file to export functions getModuleName, setInterpreter and primAdd.  I
put the DLL file in the same directory as the VM, image file, etc.

Then, in Squeak (2.8, more or less), I made a class with a method that
calls primitive 'primAdd' in module 'Adder'.  I called this method
with two small integers, and the primitive failed (went on to the
Smalltalk code after the primitive, which returns nil).

So, can anyone help?  Am I missing something obvious?

Thanks...

Alan deLespinasse



/* adder.c */
/* Automatically generated from Squeak on #(6 August 2000 3:05:09 pm) */

#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

/* Default EXPORT macro that does nothing (see comment in sq.h): */
#define EXPORT(returnType) returnType

/* Do not include the entire sq.h file but just those parts needed. */
/*  The virtual machine proxy definition */
#include "sqVirtualMachine.h"
/* Configuration options */
#include "sqConfig.h"
/* Platform specific definitions */
#include "sqPlatformSpecific.h"

#define true 1
#define false 0
#define null 0  /* using 'null' because nil is predefined in Think C */

/* memory access macros */
#define byteAt(i) (*((unsigned char *) (i)))
#define byteAtput(i, val) (*((unsigned char *) (i)) = val)
#define longAt(i) (*((int *) (i)))
#define longAtput(i, val) (*((int *) (i)) = val)

/*** Variables ***/
struct VirtualMachine* interpreterProxy;
const char *moduleName = "Adder 6 August 2000 (e)";

/*** Function Prototypes ***/
#pragma export on
EXPORT(const char*) getModuleName(void);
EXPORT(int) setInterpreter(struct VirtualMachine* anInterpreter);
EXPORT(int) primAdd(void);
#pragma export off

EXPORT(const char*) getModuleName(void) {
	return moduleName;
}

EXPORT(int) setInterpreter(struct VirtualMachine* anInterpreter) {
    int ok;

	interpreterProxy = anInterpreter;
	ok = interpreterProxy->majorVersion() == VM_PROXY_MAJOR;
	if (ok == 0) {
		return 0;
	}
	ok = interpreterProxy->minorVersion() >= VM_PROXY_MINOR;
	return ok;
}

EXPORT(int) primAdd(void) {
  int sum = interpreterProxy->stackIntegerValue(0) +
    interpreterProxy->stackIntegerValue(1);
  interpreterProxy->pop( 3 );
  interpreterProxy->pushInteger( sum );
  return 1;
}






More information about the Squeak-dev mailing list