[Vm-dev] Re: FFI syntax

Igor Stasenko siguctua at gmail.com
Fri Mar 25 12:54:52 UTC 2011


On 25 March 2011 13:39, Torsten Bergmann <astares at gmx.de> wrote:
>
>>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.
>

Yes. It is heretic.
A plain copy-pasting of C code don't makes your application more
readable or easier to use.
So i prefer to see it only in a single place, where you interfacing
with foreign functions, but nowhere else in code.

> 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.
>

Andreas and others with Croquet background could tell you more why
positional arguments syntax
were failed (in a sense that people decided to not use it, but use
normal keyword syntax instead).

> Bye
> T.
>
> --
> GMX DSL Doppel-Flat ab 19,99 Euro/mtl.! Jetzt mit
> gratis Handy-Flat! http://portal.gmx.net/de/go/dsl
>



-- 
Best regards,
Igor Stasenko AKA sig.


More information about the Vm-dev mailing list