how to write a wrapper?
- Posted by Jules <jdavy at dsl.pip?x.co?> Aug 02, 2007
- 501 views
most of the Euphoria "heavyweights" (as opposed to the "lightweights", like me) devote much of their time and effort into wrapping libraries to extend Eu's functionality. I understand the basic mechanics of this: There are actually 3 steps to go through. 1/ Your wrapper must open a shared file (.dll on Windows, .so on Linux/BSD) using open_dll() (be sure to include machine.e). This function will return some atom I'll call entry_point. 2/ For each routine you need to wrap, define a constant representing that routine using defie_c_func (or _proc): constant the_func=define_c_func(entry_point,func_name,arg_type_list,return_type) You can also access public variables using define_c_var(). 3/ Then, in any program using the routines, including your own wrapper, you use c_func() or c_proc() to call the routine, using the identifiers defined in stage 2 as routine ids. And that should be all, unless you have to fiddle with calling convention. If the doc for your dll talks about cdecl, then there is a specific syntax to use in define_c_func. (thanks to CChris for this post). I'd like to have a go at writing a simple wrapper but am unsure where to start. I assume I don't need much knowledge of C, but surely I need some? and if so, what, particularly? I don't (hopefully) need spoon-feeding, but if someone could point me in the right direction, that would be great. I'm sure there are many other Eu coders who would like to see a tutorial on this subject. I'd be happy to write one myself, once I've learned the basics.