moo/moo/kernel/FFI.moo
hyunghwan.chung 4656bf128e added a new class variable declarator 'var' or 'variable'
supported  | .. | style declartion at the class level.
added the RDONLY flag to the object header
wrote some code to support default values for class-level variables such as instance variables
2017-04-19 16:46:44 +00:00

56 lines
879 B
Smalltalk

class _FFI(Object) from 'ffi'
{
method(#primitive) open(name).
method(#primitive) close.
method(#primitive) getsym(name).
(* TODO: make call variadic? method(#primitive,#variadic) call (func, sig). *)
method(#primitive) call(func, sig, args).
}
class FFI(Object)
{
var 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, args)
}
}