createChildFor aWidget:Widget
{ creator -> aWidget.
widgetid -> CALL Motif(56):Integer.
}
This example is taken from type Window
and is used to create a window. The windowing system itself is treated as an
external subsystem. The subsystem known within ABC as "Motif" is called
with the receiver of the 'createChildFor:' message put on the ABC stack
followed by the objects listed in the parameter list. Once this function is
complete, it will reply with an object. Since ABC can't know the type of
the object, the type is supplied via typecasting.
/* Install your external function in initExternal and call the initialization
procedure for your external system(if needed).
Call the exit function in exitExternal (if needed). */
int initExternal()
{
int Motif(),XlibGlue(),installExternal(),Matrix(); /*
int i;
for (i = 0; i < MAXEXT; i++)
ExtTable[i].hash = 0;
/* install your main routine here */
installExternal("Motif",Motif);
installExternal("Xlib",XlibGlue);
installExternal("Matrix",Matrix);
/* initialize if necessary */
if (!SystemMode) {
MotifInit();
XlibInit();
InitMatrix();
};
}
/* exit if necessary */
int exitExternal()
{
if (!SystemMode) {
MotifExit();
MatrixExit();
};
}
Your source code file for Matrix should look something like:
#include "dconstant.h" #include "dobject.h" #include "globals.h"int Matrix() /* note that there are no parameters */ { /* put your code here */ }
Finally copy /home/abc/env/Makefile to your directory and change the extendop lines and add the matrix lines to read:
Also add matrix.o to the definition of ABCOBJS.extendop.o: extendop.c # co *.c $(CC) $(CFLAGS) *.c matrix.o: matrix.c $(CC) $(CFLAGS) *.c
You should then be able to type 'make' to build your own ABC image.
aMethod { CALL Matrix(5). }
When the CALL statement is executed in ABC, all the parameters in the CALL statement are pushed on the ABC stack and then control is passed to your C procedure. While in your procedure, you may gain access to the parameters via the following macros or procedures:
You should exercise caution in using these pointers. If you do any ABC memory allocation within your C routines, these pointers may become invalid. In such cases, you should reexecute the above code to get the correct values.DPointer *p,*q;
p = ptrparm(3); /* get the third parameter */ q = GetPtr(p,5); /* get the fifth part */
Before your function returns, you must push a value back on the stack which is the REPLY object. You can use the following functions or macros to accomplish this:
aMethod { i -> CALL Matrix(5):Integer. }