Spaces:
Running
Running
File size: 1,407 Bytes
8f3f8db |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
/*
* This is a template for a SqueakJS plugin
*
* The file would need to be imported like the other plugins,
* see squeak.js
*
* The plugin could be used from the image like this:
*
* primXyz: arg1 with: arg2
* <primitive: 'primitiveXYZ' module: 'ExamplePlugin'>
* ^self primitiveFailed
*/
function ExamplePlugin() {
"use strict";
return {
getModuleName: function() { return 'ExamplePlugin'; },
interpreterProxy: null,
primHandler: null,
setInterpreter: function(anInterpreter) {
this.interpreterProxy = anInterpreter;
this.primHandler = this.interpreterProxy.vm.primHandler;
return true;
},
primitiveXYZ: function(argCount) {
if (argCount !== 2) return false;
var arg1 = this.interpreterProxy.stackObjectValue(1);
var arg2 = this.interpreterProxy.stackIntegerValue(0);
if (this.interpreterProxy.failed()) return false;
// see vm.interpreter.proxy.js for available proxy methods
var result = this.doSomething(arg1, arg2);
this.interpreterProxy.popthenPush(argCount + 1, result);
return true;
},
};
}
function registerExamplePlugin() {
if (typeof Squeak === "object" && Squeak.registerExternalModule) {
Squeak.registerExternalModule('ExamplePlugin', ExamplePlugin());
} else self.setTimeout(registerExamplePlugin, 100);
};
registerExamplePlugin();
|