1. Passing a pointer of function to a c function

Please could anyone help me to use this c function thanks.

SWHANDLE SWModule_doSearch(SWHANDLE hmodule, const char *searchString, int type,
int params ,void (*percent) (char, void *), void *percentUserData)

it's the bit that points to a function that I am not sure how to get it to work
in Euphoria: void (*percent) (char, void *)

this is the euphoria that imports this function.
SWModSearch = define_c_func(swordLib, "SWModule_doSearch", {C_POINTER, C_CHAR,
C_INT, C_INT, C_POINTER, C_POINTER}, C_POINTER)
global function EuSWModSearch(atom mod, sequence searchString, atom searchType,
atom params ,atom percent, atom percentUserData)
atom listPtr, searchStringPtr, percentPtr, percentUserDataPtr
sequence listKey, element

searchStringPtr = allocate_string(searchString)

percentPtr = allocate(4)
percentUserDataPtr = allocate(4)

listPtr = c_func(SWModSearch,{mod, searchStringPtr, searchType, params,
percentPtr, percentUserDataPtr})

if listPtr != NULL then

  element = getListKeyVal(listPtr)

  while element != NULL do

	listKey = append(listKey, element)
	listKeyNext(listPtr)
	element = getListKeyVal(listPtr)
  end while

end if


return listKey

end function


Thanks for your help

David


new topic     » topic index » view message » categorize

2. Re: Passing a pointer of function to a c function

David Ryder wrote:
> 
> Please could anyone help me to use this c function thanks.
> 
> SWHANDLE SWModule_doSearch(SWHANDLE hmodule, const char *searchString, int
> type,
> int params ,void (*percent) (char, void *), void *percentUserData) 
> 
> it's the bit that points to a function that I am not sure how to get it to
> work
> in Euphoria: void (*percent) (char, void *)
> 
> this is the euphoria that imports this function.
SWModSearch = define_c_func(swordLib, "SWModule_doSearch", {C_POINTER, C_CHAR,
C_INT, C_INT, C_POINTER, C_POINTER},
C_POINTER)
global function EuSWModSearch(atom mod, sequence searchString, atom searchType,
atom params ,atom


You want to use call_back():
constant EuSWModSearch_cb = call_back( routine_id("EuSWModSearch") )


Matt

new topic     » goto parent     » topic index » view message » categorize

3. Re: Passing a pointer of function to a c function

thanks Matt

What I would really like to do would be to figure out how to wrap the original
C++ code for this library

However, the developers provide a c wrapper which I am using at the moment.

I have looked at the wxEuphoria library and the numerous posts on this forum,
but decided that it will have to wait till i have more time

I have got the function to work, using call_back as you suggested.

David

new topic     » goto parent     » topic index » view message » categorize

4. Re: Passing a pointer of function to a c function

David Ryder wrote:
> 
> thanks Matt
> 
> What I would really like to do would be to figure out how to wrap the original
> C++ code for this library
> 
> However, the developers provide a c wrapper which I am using at the moment.

Please don't. :P Continue using the C wrapper.  C++ is not really worth the
headaches, especially if you've already been given a wrapper with a C
interface.

> I have looked at the wxEuphoria library and the numerous posts on this forum,
> but decided that it will have to wait till i have more time

I've changed the was wxEuphoria works.  I've written my own C++ wrapper
that exports a C interface for euphoria to use.  I feel 10 years younger...

Matt

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu