On Feb 13, 2010, at 8:43 PM, Matt Gushee wrote:

> * I think I need to start by calling FT_Init_FreeType, right? Well,
>   that has a stack effect of ( library -- FT_Error ). What I don't
>   get is, where does the 'library' argument come from? I tried 

When calling a C function, the arguments in Factor map directly to the 
arguments in C. Looking at the FreeType docs at 
http://freetype.sourceforge.net/freetype2/docs/reference/ft2-toc.html, the 
"library" argument is an out parameter that points to an FT_Library (itself a 
pointer type) that gets filled with the library handle. You can use <void*> to 
allocate a byte array large enough to receive the value, then *void* to 
interpret it into an "alien" object (the Factor representation of a pointer). 
Something like this:

SYMBOL: freetype-library
f <void*> [ FT_Init_FreeType drop ] keep *void*
freetype-library set

(I'm dropping the error code return value, but in real code, you would want to 
check it and throw a Factor error on failure there.) You can then use that 
value as the "library" parameter to other FreeType calls. There are <type> and 
*type words for all the basic C types that you can use to handle other out 
pointer parameters like this. For parameters of primitive value types, Factor 
handles the conversion for you. "char*" typed parameters convert between Factor 
strings and UTF-8 encoded C strings. Structs and struct pointers and handled 
with "struct" objects on the Factor side, which behave similarly to Factor 
tuples. So you could call FT_New_Face (which takes a library, a pathname, and a 
face index, and an FT_Face output parameter) like this:

freetype-library get
"/path/to/font.ttf" 0 f <void*> [ FT_New_Face drop ] *void*

Again, you should type «"alien" help» in the listener for full documentation on 
the C FFI.

-Joe
------------------------------------------------------------------------------
SOLARIS 10 is the OS for Data Centers - provides features such as DTrace,
Predictive Self Healing and Award Winning ZFS. Get Solaris 10 NOW
http://p.sf.net/sfu/solaris-dev2dev
_______________________________________________
Factor-talk mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/factor-talk

Reply via email to