Removed all code that uses OpenGL from Image.
[io/quag.git] / addons / CFFI / source / IoCFFILibrary.c
blob0fed3ea88019a4c94aa07a40ab6f5ae3a4bfa89a
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.
4 */
6 #include "IoCFFILibrary.h"
7 #include <string.h>
8 #include "IoSeq.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);
18 return tag;
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[] = {
32 {NULL, NULL},
34 IoObject_addMethodTable_(self, methodTable);
37 return self;
40 IoCFFILibrary *IoCFFILibrary_rawClone(IoCFFILibrary *proto)
42 IoObject *self = IoObject_rawClonePrimitive(proto);
43 IoObject_setDataPointer_(self, calloc(1, sizeof(IoCFFILibraryData)));
44 return self;
47 void IoCFFILibrary_free(IoCFFILibrary *self)
49 DynLib *library = DATA(self)->library;
51 if (library && DynLib_isOpen(library))
53 DynLib_close(library);
54 DynLib_free(library);
57 free(DATA(self));
60 /* ---------------------------------------------------------------- */
62 void *IoCFFILibrary_rawGetFuctionPointer_(IoCFFILibrary *self, const char *name)
64 DynLib *library = DATA(self)->library;
66 if (!library)
68 const char *name = CSTRING(IoObject_getSlot_(self, IOSYMBOL("name")));
70 library = DATA(self)->library = DynLib_new();
71 DynLib_setPath_(library, name);
72 DynLib_open(library);
75 return DynLib_pointerForSymbolName_(library, name);