In order to bind more easily to SDL I have added a bit of new grammar. 1. In a struct or cstruct you can now write
name : type; as usual or type name; for elements. For example: struct X { x: int; int y; }; is valid. Note the type must be a valid Felix type. So type names like "char *" or "void *" in the C form will not (currently) work. 2. Felix now recognizes this hackery: typedef struct { ... } typename; typedef struct typename1 { ... } typename2; In the second form, typename1 and typename2 must be identical. This syntax makes a cstruct NOT a struct, that is, it doesn't define any struct, just binds to an existing C one. As a result of this, I have been able to lift many type definitions straight from SDL header files with only trivial modifications. This is much easier than laboriously changing int x to x: int for every field! For example this C: /** * \brief A user-defined event type (event.user.*) */ typedef struct SDL_UserEvent { Uint32 type; /**< ::SDL_USEREVENT through ::SDL_LASTEVENT-1 */ Uint32 timestamp; Uint32 windowID; /**< The associated window if any */ Sint32 code; /**< User defined event code */ void *data1; /**< User defined data pointer */ void *data2; /**< User defined data pointer */ } SDL_UserEvent; translates to this Felix: /** * \brief A user-defined event type (event.user.*) */ typedef struct SDL_UserEvent { uint32 type; /**< ::SDL_USEREVENT through ::SDL_LASTEVENT-1 */ uint32 timestamp; uint32 windowID; /**< The associated window if any */ int32 n"code"; /**< User defined event code */ address data1; /**< User defined data pointer */ address data2; /**< User defined data pointer */ } SDL_UserEvent; A quick global change on the integer types was done. A void* is changed to address. And the field name "code" caused Felix to barf, so I used this: n"code" In case you haven't seen this one before: this is a string form that represents an identifier with ANY sequence of characters. It is necessary here because cstructs bind field names from felix to C and there's no way other simple way to lift a C identifier which is a Felix "keyword" thing in a particular context. Note "type" didn't barf, the parser knew it wasn't the statement "type ...". Note that cstruct can be used for unions too. However there's a caveat (BUG!) for all cstructs: if they're not full models of the C struct being bound to, then constructors based on tuples will silently fail (i.e. write garbage all over the place). This is because Felix reinterpret casts a tuple to the relevant struct, and the cast will only put things in the right place if the struct for the tuple and the specified C struct are layout compatible. in case you haven't seen them, check out cenum cflags as well. The map **named** C enumerations (you have to use "const" for an unnamed enumeration or the type binding fails). cenum supports equality operator. cflags also supports bitwise operators. I will look to see if C function prototypes can also be handled a bit more easily too (something like cfunc type name (type arg, ...); might work. Note cfun is unrelated! cfun defines a Felix function which must be translated to a C function with the exact same signature as a C function type, and can thus be used as a callback, whereas cfunc (bad name I know) would just be a binding. -- john skaller skal...@users.sourceforge.net http://felix-lang.org ------------------------------------------------------------------------------ This SF.net email is sponsored by Windows: Build for Windows Store. http://p.sf.net/sfu/windows-dev2dev _______________________________________________ Felix-language mailing list Felix-language@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/felix-language