1 /* CFFI - An Io interface to C
2 Copyright (c) 2006 Trevor Fancher. All rights reserved.
3 All code licensed under the New BSD license.
6 #include "IoCFFILibrary.h"
10 #define DATA(self) ((IoCFFILibraryData *)(IoObject_dataPointer(self)))
12 IoTag
*IoCFFILibrary_newTag(void *state
)
14 IoTag
*tag
= IoTag_newWithName_("Library");
15 IoTag_state_(tag
, state
);
16 IoTag_freeFunc_(tag
, (IoTagFreeFunc
*)IoCFFILibrary_free
);
17 IoTag_cloneFunc_(tag
, (IoTagCloneFunc
*)IoCFFILibrary_rawClone
);
21 IoCFFILibrary
*IoCFFILibrary_proto(void *state
)
23 IoObject
*self
= IoObject_new(state
);
24 IoObject_tag_(self
, IoCFFILibrary_newTag(state
));
26 IoObject_setDataPointer_(self
, calloc(1, sizeof(IoCFFILibraryData
)));
28 IoState_registerProtoWithFunc_(state
, self
, IoCFFILibrary_proto
);
31 IoMethodTable methodTable
[] = {
34 IoObject_addMethodTable_(self
, methodTable
);
40 IoCFFILibrary
*IoCFFILibrary_rawClone(IoCFFILibrary
*proto
)
42 IoObject
*self
= IoObject_rawClonePrimitive(proto
);
43 IoObject_setDataPointer_(self
, calloc(1, sizeof(IoCFFILibraryData
)));
47 void IoCFFILibrary_free(IoCFFILibrary
*self
)
49 DynLib
*library
= DATA(self
)->library
;
51 if (library
&& DynLib_isOpen(library
))
53 DynLib_close(library
);
60 /* ---------------------------------------------------------------- */
62 void *IoCFFILibrary_rawGetFuctionPointer_(IoCFFILibrary
*self
, const char *name
)
64 DynLib
*library
= DATA(self
)->library
;
68 const char *name
= CSTRING(IoObject_getSlot_(self
, IOSYMBOL("name")));
70 library
= DATA(self
)->library
= DynLib_new();
71 DynLib_setPath_(library
, name
);
75 return DynLib_pointerForSymbolName_(library
, name
);