Files
moo/moo/kernel/FFI.moo
hyunghwan.chung 71aa1110ed added more preamable codes.
enhanced the system to be able to attach trailing spaces to an object upon instantiation, especially for external modules to be able to secure GC-safe free workspace inside an instantiated object
added moo_setclasstrsize(), moo_getobjtrailer() for the trailer feature
2017-02-14 08:29:30 +00:00

59 lines
903 B
Plaintext

class _FFI(Object) from 'ffi'
{
(*
* the ffi module installs the following methods
* method(#class) _newInstSize
* method open: name
* method close
* method call
* method call: func sig: sig with: args.
*)
}
class FFI(Object)
{
dcl name ffi funcs.
method(#class) new: aString
{
^self new open: aString.
}
method initialize
{
self.funcs := Dictionary new.
self.ffi := _FFI new.
}
method open: name
{
| x |
self.funcs removeAllKeys.
self.name := name.
x := self.ffi open: name.
(x isError) ifTrue: [^x].
^self.
}
method close
{
self.ffi close.
}
method call: name signature: sig arguments: args
{
| f |
f := self.funcs at: name.
(f isError) ifTrue: [
f := self.ffi getsym: name.
(f isError) ifTrue: [^f].
self.funcs at: name put: f.
].
(*^self.ffi call: f sig: sig with: args*)
^self.ffi call(f, sig, args)
}
}