Re: C Struct Support
- Posted by jimcbrown (admin) Dec 30, 2010
- 1803 views
petelomax said...
I was thinking more of something like:
cstruct:structure("APPBARDATA",""" DWORD cbSize; // sizeof(APPBARDATA) HWND hWnd; // handle of appbar UINT uCallbackMessage; // see below UINT uEdge; // see below RECT rc; // see below LPARAM lParam; """) ABD = cstruct:new("APPBARDATA") cstruct:set(ABD,"uEdge",ABE_LEFT) ? cstruct:get(ABD,"uEdge")
I assume there is little need for "static" c-structs; them all being allocated on the heap is plenty good enough. (I expect ABD to be an {index,ptr}, btw.) The obvious benefit is you don't have to do the line-by-line translation, just cut and paste the C code.
Regards, Pete
Oh, I approve!
One practical note on the "copy & paste from C code" bit though:
But, LPARAM, RECT, etc are not defined on e.g. Linux/GNU. Aside from the basic C types (char, short, long, etc) how is the library/preprocessor to know what a given type means? If we hardcode it to know about DWORD, etc should we also hardcode it to know about uint8_t, off_t, etc?