void *const ptr);
ANN m_bool plugin_ini(struct Gwion_ *gwion, const m_str iname, const loc_t);
+struct DriverData_;
+struct Gwi_;
+typedef m_bool (*gwplugin_t) (struct Gwi_*);
+typedef void* (*gwmodini_t) (struct Gwion_ const* gwion, const Vector args);
+typedef void* (*gwmodend_t) (struct Gwion_ const* gwion, void *self);
+typedef void* (*gwdriver_t) (struct DriverData_ *);
+typedef m_str* (*gwdepend_t) (void);
+
#define GWIMPORT_NAME import
#define GWMODINI_NAME gwmodini
#define GWMODEND_NAME gwmodend
#define GWDRIVER_NAME gwdriver
#define GWDEPEND_NAME gwdepend
-#define GWMODINI(a) \
- ANN2(1) \
+
+#ifndef GWION_BUILTIN
+#define GWMODINI(a) \
+ ANN2(1) \
void *GWMODINI_NAME(struct Gwion_ *const gwion NUSED, const Vector args NUSED)
-#define GWMODEND(a) \
+#define GWMODEND(a) \
ANN void GWMODEND_NAME(struct Gwion_ *const gwion NUSED, void *self NUSED)
#define GWDRIVER(a) ANN void GWDRIVER_NAME(DriverData *d)
-#define GWDEPEND ANN m_str const *GWDEPEND_NAME(void)
+#define GWDEPEND(a) ANN m_str const *GWDEPEND_NAME(void)
+#else
+#define GWIMODINI(a) \
+ ANN2(1) \
+ void *gwmodini_##a(struct Gwion_ *const gwion NUSED, const Vector args NUSED)
+#define GWMODEND(a) \
+ ANN void gwmodend_##a(struct Gwion_ *const gwion NUSED, void *self NUSED)
+#define GWDRIVER(a) gwdriver_##a(a) ANN void GWDRIVER_NAME(DriverData *d)
+#define GWDEPEND(a) gwdepend_##a ANN m_str const *GWDEPEND_NAME(void)
+#endif
#endif
#include "gwi.h"
typedef m_bool (*plugin)(Gwi);
-typedef void *(*modini)(const struct Gwion_ *, const Vector);
-typedef void *(*modend)(const struct Gwion_ *, void *);
-typedef m_str *(*gwdeps)(void);
struct PlugHandle {
MemPool mp;
void *dl;
void *self;
Nspc nspc;
+ gwplugin_t plugin;
+ gwdriver_t driver;
+ gwmodini_t modini;
+ gwmodend_t modend;
+ gwdepend_t depend;
} * Plug;
ANN static struct Plug_ *new_plug(MemPool p, void *dl) {
struct Plug_ *plug = mp_calloc(p, Plug);
plug->dl = dl;
+ plug->plugin = DLSYM(plug->dl, gwplugin_t, GWIMPORT_NAME);
+ plug->modini = DLSYM(plug->dl, gwmodini_t, GWMODINI_NAME);
+ plug->modend = DLSYM(plug->dl, gwmodend_t, GWMODEND_NAME);
+ plug->depend = DLSYM(plug->dl, gwdepend_t, GWDEPEND_NAME);
return plug;
}
const Map map = &gwion->data->plugs->map;
for (m_uint i = 0; i < map_size(map); ++i) {
const Plug plug = (Plug)VVAL(map, i);
- const modend end = DLSYM(plug->dl, modend, GWMODEND_NAME);
+ const gwmodend_t end = plug->modend;
if (end && plug->self) end(gwion, plug->self);
free((m_str)VKEY(map, i));
DLCLOSE(plug->dl);
if (!strcmp(name, (m_str)VKEY(map, j))) {
Plug plug = (Plug)VVAL(map, j);
const Vector arg = opt ? split_args(gwion->mp, opt) : NULL;
- const modini ini = DLSYM(plug->dl, modini, GWMODINI_NAME);
- plug->self = ini(gwion, arg);
+ if(!plug->modini) continue;
+ plug->self = plug->modini(gwion, arg);
if (arg) plug_free_arg(gwion->mp, arg);
break;
}
}
ANN static m_bool dependencies(struct Gwion_ *gwion, const Plug plug, const loc_t loc) {
- const gwdeps dep = DLSYM(plug->dl, gwdeps, GWDEPEND_NAME);
+ const gwdepend_t dep = plug->depend;
bool ret = true;
if (dep) {
m_str *const base = dep();
}
ANN static m_bool start(const Plug plug, const Gwion gwion, const m_str iname, const loc_t loc) {
- const plugin imp = DLSYM(plug->dl, plugin, GWIMPORT_NAME);
+ if(!plug->plugin) return GW_ERROR;
const bool cdoc = gwion->data->cdoc;
gwion->data->cdoc = 0; // check cdoc
CHECK_BB(dependencies(gwion, plug, loc));
const m_uint scope = env_push(gwion->env, NULL, plug->nspc);
const m_str name = gwion->env->name;
gwion->env->name = iname;
- const m_bool ret = gwi_run(gwion, imp);
+ const m_bool ret = gwi_run(gwion, plug->plugin);
gwion->env->name = name;
env_pop(gwion->env, scope);
return ret;