No more FFI code to copy from

Lendvai Attila Attila.Lendvai at netvisor.hu
Wed Mar 30 00:45:27 PST 2005


:: I was using code like windows.slate as a model to do SDL FFI
:: stuff. But I don't find example that actually use the
:: structure (maybe I'm just blind).
::
:: What would be cool is if I had an example with a C function
:: receiving a pointer on a 2D-Point Structure, and would fill
:: it with let's say (x=6, y=2), and would return it. Then the
:: Slate code, would allocate a 2D-Point structure, give a
:: pointer to the C function, and retrieve the x and y values.
::
:: Is asking someone to do this to show me how it is done, is
:: asking too much?

I've got way less energy for Slate then I would like to have...

the windows.slate contains many examples:

c@(WindowsConsole traits) screenBufferInfo
[| info |
  info: Windows CONSOLE_SCREEN_BUFFER_INFO clone.
  (Windows Kernel GetConsoleScreenBufferInfo applyTo: {c consoleOut.
info})
    ifFalse: [error: 'Failed to get screen buffer info'. ^ Nil].
  info
].

Here "Windows CONSOLE_SCREEN_BUFFER_INFO" is a ByteArray with the extra
struct element accessors added by FFI (this happens while loading
kernel.slate). You can simply clone it (see above) and use it's
accessors:

c@(WindowsConsole traits) updateBufferWindowPositionFrom: info
[
  c bufferWindowPosition ifNil: [c bufferWindowPosition: {0. 0}].
  c bufferWindowPosition at: 0 put: info srWindow_Left.
  c bufferWindowPosition at: 1 put: info srWindow_Top.
  c moveCursorTo: {c actualCursorColumnIn: info. c actualCursorRowIn:
info}.
].

Here "info srWindow_Left" is such an accessor... but there are mutators,
too.

Another method with full of examples:

c@(WindowsConsole traits) scroll &lines: lines
[| info entire dest |
  c assumeStructuredMode.
  lines ifNil: [lines: 1].
  info: c screenBufferInfo.
  entire: Windows SMALL_RECT clone.
  dest: Windows COORD clone.

  entire `>> [Top: 1. Left: 0. Bottom: info dwSize_Y - 1. Right: info
dwSize_X - 1].
  dest X: 0.
  dest Y: 0.

  Windows Kernel ScrollConsoleScreenBufferA applyTo:
    {c consoleOut. entire. entire. dest. c clearChar}.
  c updateBufferWindowPosition.
].

Hope it helps,

- 101

-------------- next part --------------
An HTML attachment was scrubbed...
URL: /archives/slate/attachments/20050330/bb4afaa2/attachment.htm


More information about the Slate mailing list