DynamicLibrary for unix

Tony Garnock-Jones tonyg at lshift.net
Wed Oct 27 09:59:10 PDT 2004


Hi all.

Attached is a patch implementing a DynamicLibrary object which allows 
the use of .so files containing primitives, which are loaded into the VM 
at runtime. It's quite basic, but so far code like this works:

[| d h |

   d: (DynamicLibrary newNamed: 'testplugin').
   h: (d lookup: 'addSmallInts').
   (h applyWith: 3 with: 4) printOn: Console writer.
   Console ; '\n'.
] do.


when run against a plugin like this one:

/* libtool --mode=compile gcc -o testplugin.lo -c testplugin.c */
/* libtool --mode=link gcc -module -o testplugin.la testplugin.lo
      -rpath `pwd` */
#include "slatevm.h"

ObjectPointer addSmallInts(ObjectPointer *argv, unsigned long int argc) {
   signed long int a = ObjectPointer_asSmallInt(argv[0]);
   signed long int b = ObjectPointer_asSmallInt(argv[1]);
   return signedLongInt_asObject(a + b);
}


So far I've tried it on Debian Linux on x86 and Macos X on PPC. Porting 
to Windows ought to be trivial: instead of dlopen/dlsym/dlclose from 
dlfcn.h, use LoadLibrary/GetProcAddress/FreeLibrary from windows.h. Of 
course, I've no idea what to use instead of libtool on Windows :-)

Regards,
   Tony
-------------- next part --------------
A non-text attachment was scrubbed...
Name: dynlib-patch.tar.gz
Type: application/x-gzip
Size: 3955 bytes
Desc: not available
Url : /archives/slate/attachments/20041027/fffde33d/dynlib-patch.tar.bin


More information about the Slate mailing list