[Haskell-cafe] FFI Ptr Question
Michael Jones
mike at proclivis.com
Sun Apr 5 07:11:11 UTC 2015
I am having trouble figuring out how to pass callbacks to C.
Given the definition below it is not clear how to define a function and pass it. I tried:
getNumberOfRows :: CInt
getNumberOfRows = 1
table <- wxcGridTableCreate getNumberOfRows…
but the compiler barks at me:
src/MainGui.hs:577:32: Not in scope: data constructor ‘Ptr’
even through I do the imports:
import Foreign
import Foreign.C
There is also a _obj as the first value of wxcGridTableCreate and the callbacks, and I am not sure how to make a this* for it. I would have throughout that wxcGridTableCreate would return a Ptr.
The goal is to pass haskell functions into wxcGridTableCreate so the grid can call back to haskell.
Can someone show an example of just this one function, how to wrap a Ptr around it, and what to do with _obj?
DEFINITION
wxcGridTableCreate :: Ptr a -> Ptr b -> Ptr c -> Ptr d -> Ptr e -> Ptr f -> Ptr g -> Ptr h -> Ptr i -> Ptr j -> Ptr k -> Ptr l -> Ptr m -> Ptr n -> Ptr o -> Ptr p -> Ptr q -> IO (WXCGridTable ())
wxcGridTableCreate _obj _EifGetNumberRows _EifGetNumberCols _EifGetValue _EifSetValue _EifIsEmptyCell _EifClear _EifInsertRows _EifAppendRows _EifDeleteRows _EifInsertCols _EifAppendCols _EifDeleteCols _EifSetRowLabelValue _EifSetColLabelValue _EifGetRowLabelValue _EifGetColLabelValue
= withObjectResult $
wx_ELJGridTable_Create _obj _EifGetNumberRows _EifGetNumberCols _EifGetValue _EifSetValue _EifIsEmptyCell _EifClear
_EifInsertRows _EifAppendRows _EifDeleteRows _EifInsertCols _EifAppendCols _EifDeleteCols
_EifSetRowLabelValue _EifSetColLabelValue _EifGetRowLabelValue _EifGetColLabelValue
foreign import ccall "ELJGridTable_Create" wx_ELJGridTable_Create :: Ptr a -> Ptr b -> Ptr c -> Ptr d -> Ptr e -> Ptr f -> Ptr g -> Ptr h -> Ptr i -> Ptr j -> Ptr k -> Ptr l -> Ptr m -> Ptr n -> Ptr o -> Ptr p -> Ptr q -> IO (Ptr (TWXCGridTable ()))
typedef int _cdecl (*TGridGetInt)(void* _obj);
typedef int _cdecl (*TGridIsEmpty)(void* _obj, int row, int col);
typedef void* _cdecl (*TGridGetValue)(void* _obj, int row, int col);
typedef void _cdecl (*TGridSetValue)(void* _obj, int row, int col, void* val);
typedef void _cdecl (*TGridClear)(void* _obj);
typedef int _cdecl (*TGridModify)(void* _obj, int pos, int num);
typedef int _cdecl (*TGridMultiModify)(void* _obj, int num);
typedef void _cdecl (*TGridSetLabel)(void* _obj, int idx, void* val);
typedef void* _cdecl (*TGridGetLabel)(void* _obj, int idx);
EWXWEXPORT(void*,ELJGridTable_Create)(void* self,void* _EifGetNumberRows,void* _EifGetNumberCols,void* _EifGetValue,void* _EifSetValue,void* _EifIsEmptyCell,void* _EifClear,void* _EifInsertRows,void* _EifAppendRows,void* _EifDeleteRows,void* _EifInsertCols,void* _EifAppendCols,void* _EifDeleteCols,void* _EifSetRowLabelValue,void* _EifSetColLabelValue,void* _EifGetRowLabelValue,void* _EifGetColLabelValue)
{
return (void*)new ELJGridTable (self,
More information about the Haskell-Cafe
mailing list