[Vm-dev] Re: FFI syntax
Torsten Bergmann
astares at gmx.de
Fri Mar 25 12:39:35 UTC 2011
>This has not much to do with FFI syntax itself.
You dont get my point. I've often seen Smalltalkers
that want to stay "smalltalkish" in syntax even when
using external stuff.
In Squeak's FFI we use <...> annotation for FFI.
ST/MT made it (by using WINAPI shadow class) a little
bit easier since you can think of a C-function call
as a keyword message with n arguments (#foo:with:with: selectors).
That is more familiar for typical Smalltalkers. You can also
use "NULL" or created PoolDictionaries from header files, so one
can use the C constants like "MB_YESNO", ...
Remember the discussion to allow underscores in Squeak? ;)
>That's how the OpenGL bindings work in Croquet, for example. As a user you >just call the OpenGL functions, someone else took care of providing the >FFI calls.
Which syntax did you use for the OpenGL function calls?
David followed an approach in Smallscript/S# where you were
able (beside the usual Smalltalk syntax) to also use
a C-Style syntax with braces directly within Smalltalk.
User32::MessageBox(NULL,'Hello','World',0)
was similar to
User32::MessageBox: NULL with: 'Hello' with: 'World' with: 0
Both worked and was accepted by the parser, although the first one
looked heretic to most Smalltalkers since you can mix C/Smalltalk
syntax the way you like.
So you just attached a DLL to a class
Class name: OpenGLControl
extends: UIControl
dll: opengl32
fields: context
and you could write:
onCustomDraw: facet
|hdc| := thread activeCanvas hDC.
...
glClear(GL_COLOR_BUFFER_BIT).
glBegin(GL_TRIANGLES).
glColor3ub(255, 0, 0).
glVertex2i(0, 1).
...
This was open/more familiar to people coming from C/C++ background
or when converting C examples to Smalltalk.
Bye
T.
--
GMX DSL Doppel-Flat ab 19,99 Euro/mtl.! Jetzt mit
gratis Handy-Flat! http://portal.gmx.net/de/go/dsl
More information about the Vm-dev
mailing list