moo/stix/kernel/Moo.st

87 lines
1.6 KiB
Smalltalk
Raw Normal View History

#include 'Apex.st'.
#include 'Context.st'.
#include 'Except.st'.
#include 'Class.st'.
#include 'Boolean.st'.
#include 'Magnitu.st'.
2016-05-18 14:53:20 +00:00
#include 'Collect.st'.
2015-10-15 14:40:08 +00:00
#include 'Process.st'.
class FFI(Object)
{
dcl name handle funcs.
method(#class) new: aString
{
^self new open: aString.
}
method open: aString
{
self.funcs := Dictionary new.
self.name := aString.
2015-10-14 13:25:36 +00:00
self.handle := self privateOpen: self.name.
"[ self.handle := self privateOpen: self.name ]
on: Exception do: [
]
on: XException do: [
]."
^self.
}
method close
{
self privateClose: self.handle.
self.handle := nil.
}
method call: aFunctionName withSig: aString withArgs: anArray
{
| f |
## f := self.funcs at: aFunctionName.
## f isNil ifTrue: [
## f := self privateGetSymbol: aFunctionName in: self.handle.
## f isNil ifTrue: [ self error: 'No such function' ].
## self.funcs at: aFunctionName put: f.
## ].
f := self privateGetSymbol: aFunctionName in: self.handle.
f isNil ifTrue: [ self error: 'No such function' ].
^self privateCall: f withSig: aString withArgs: anArray
}
method privateOpen: aString
{
2015-10-15 14:40:08 +00:00
<primitive: #_ffi_open>
^nil. ## TODO: Error signal: 'can not open'
}
method privateClose: aHandle
{
2015-10-15 14:40:08 +00:00
<primitive: #_ffi_close>
}
method privateCall: aSymbol withSig: aString withArgs: anArray
{
2015-10-15 14:40:08 +00:00
<primitive: #_ffi_call>
}
method privateGetSymbol: aString in: aHandle
{
2015-10-15 14:40:08 +00:00
<primitive: #_ffi_getsym>
^nil.
}
}
2016-05-07 01:37:44 +00:00
#########################################################################################
#include 'Stdio.st'.
#include 'Console.st'.