update nf7 iface
This commit is contained in:
@@ -20,6 +20,7 @@ for name in $@; do
|
||||
echo " nf7util_log_debug(\"loading module: %s\", nf7core_${name}.name);"
|
||||
echo " mods[i] = nf7core_${name}_new(nf7);"
|
||||
echo " if (nullptr != mods[i]) {"
|
||||
echo " assert(nullptr != mods[i]->nf7);"
|
||||
echo " assert(nullptr != mods[i]->meta);"
|
||||
echo " ++i;"
|
||||
echo " nf7util_log_info(\"loaded module: %s\", nf7core_${name}.name);"
|
||||
|
||||
@@ -20,14 +20,14 @@ struct nf7_mod* nf7core_exec_new(struct nf7* nf7) {
|
||||
|
||||
*this = (struct nf7core_exec) {
|
||||
.super = {
|
||||
.nf7 = nf7,
|
||||
.meta = &nf7core_exec,
|
||||
},
|
||||
.nf7 = nf7,
|
||||
.malloc = nf7->malloc,
|
||||
};
|
||||
|
||||
nf7core_exec_ideas_init(&this->ideas, this->malloc);
|
||||
return (struct nf7_mod*) this;
|
||||
return &this->super;
|
||||
|
||||
ABORT:
|
||||
nf7util_log_warn("aborting module init");
|
||||
@@ -46,5 +46,5 @@ const struct nf7_mod_meta nf7core_exec = {
|
||||
.desc = (const uint8_t*) "provides a registry for executables",
|
||||
.ver = NF7_VERSION,
|
||||
|
||||
.delete = del_,
|
||||
.del = del_,
|
||||
};
|
||||
|
||||
@@ -21,9 +21,9 @@ struct nf7_mod* nf7core_lua_new(struct nf7* nf7) {
|
||||
}
|
||||
*this = (struct nf7core_lua) {
|
||||
.super = {
|
||||
.nf7 = nf7,
|
||||
.meta = &nf7core_lua,
|
||||
},
|
||||
.nf7 = nf7,
|
||||
.malloc = nf7->malloc,
|
||||
.uv = nf7->uv,
|
||||
};
|
||||
@@ -33,7 +33,7 @@ struct nf7_mod* nf7core_lua_new(struct nf7* nf7) {
|
||||
nf7util_log_error("failed to create main thread");
|
||||
goto ABORT;
|
||||
}
|
||||
return (struct nf7_mod*) this;
|
||||
return &this->super;
|
||||
|
||||
ABORT:
|
||||
nf7util_log_warn("aborting lua module init");
|
||||
@@ -62,5 +62,5 @@ const struct nf7_mod_meta nf7core_lua = {
|
||||
.desc = (const uint8_t*) "lua script execution",
|
||||
.ver = NF7_VERSION,
|
||||
|
||||
.delete = del_mod_,
|
||||
.del = del_mod_,
|
||||
};
|
||||
|
||||
@@ -16,7 +16,6 @@ extern const struct nf7_mod_meta nf7core_lua;
|
||||
struct nf7core_lua {
|
||||
struct nf7_mod super;
|
||||
|
||||
const struct nf7* nf7;
|
||||
struct nf7util_malloc* malloc;
|
||||
uv_loop_t* uv;
|
||||
|
||||
|
||||
@@ -43,9 +43,9 @@ struct nf7_mod* nf7core_sdl2_new(const struct nf7* nf7) {
|
||||
}
|
||||
*this = (struct nf7core_sdl2) {
|
||||
.super = {
|
||||
.nf7 = nf7,
|
||||
.meta = &nf7core_sdl2,
|
||||
},
|
||||
.nf7 = nf7,
|
||||
.malloc = nf7->malloc,
|
||||
.uv = nf7->uv,
|
||||
};
|
||||
@@ -60,7 +60,7 @@ struct nf7_mod* nf7core_sdl2_new(const struct nf7* nf7) {
|
||||
|
||||
nf7util_signal_init(&this->event_signal, this->malloc);
|
||||
nf7core_sdl2_ref(this);
|
||||
return (struct nf7_mod*) this;
|
||||
return &this->super;
|
||||
|
||||
ABORT:
|
||||
nf7util_log_warn("initialization is aborted");
|
||||
@@ -101,5 +101,5 @@ const struct nf7_mod_meta nf7core_sdl2 = {
|
||||
.desc = (const uint8_t*) "provides SDL2 features",
|
||||
.ver = NF7_VERSION,
|
||||
|
||||
.delete = unref_,
|
||||
.del = unref_,
|
||||
};
|
||||
|
||||
@@ -21,7 +21,6 @@ struct nf7core_sdl2 {
|
||||
struct nf7_mod super;
|
||||
|
||||
// library pointers (immutable)
|
||||
const struct nf7* nf7;
|
||||
struct nf7util_malloc* malloc;
|
||||
uv_loop_t* uv;
|
||||
SDL_Window* win;
|
||||
|
||||
@@ -38,7 +38,7 @@ static struct nf7core_sdl2_poll* poll_new_(struct nf7core_sdl2* mod) {
|
||||
return nullptr;
|
||||
}
|
||||
*this = (struct nf7core_sdl2_poll) {
|
||||
.nf7 = mod->nf7,
|
||||
.nf7 = mod->super.nf7,
|
||||
.malloc = mod->malloc,
|
||||
.uv = mod->uv,
|
||||
|
||||
|
||||
@@ -24,9 +24,9 @@ struct nf7_mod* nf7core_test_new(const struct nf7* nf7) {
|
||||
}
|
||||
*this = (struct nf7core_test) {
|
||||
.super = {
|
||||
.nf7 = nf7,
|
||||
.meta = &nf7core_test,
|
||||
},
|
||||
.nf7 = nf7,
|
||||
.malloc = nf7->malloc,
|
||||
.uv = nf7->uv,
|
||||
};
|
||||
@@ -35,7 +35,7 @@ struct nf7_mod* nf7core_test_new(const struct nf7* nf7) {
|
||||
nf7util_log_error("failed to setup runner");
|
||||
return nullptr;
|
||||
}
|
||||
return (struct nf7_mod*) this;
|
||||
return &this->super;
|
||||
}
|
||||
|
||||
static void del_(struct nf7_mod* mod) {
|
||||
@@ -49,5 +49,5 @@ const struct nf7_mod_meta nf7core_test = {
|
||||
.desc = (const uint8_t*) "executes tests after the initialization",
|
||||
.ver = NF7_VERSION,
|
||||
|
||||
.delete = del_,
|
||||
.del = del_,
|
||||
};
|
||||
|
||||
@@ -14,7 +14,6 @@ struct nf7core_test_run;
|
||||
struct nf7core_test {
|
||||
struct nf7_mod super;
|
||||
|
||||
const struct nf7* nf7;
|
||||
struct nf7util_malloc* malloc;
|
||||
uv_loop_t* uv;
|
||||
|
||||
|
||||
@@ -51,7 +51,7 @@ static bool run_trigger_setup_(struct nf7core_test* mod) {
|
||||
.malloc = mod->malloc,
|
||||
.uv = mod->uv,
|
||||
.test = {
|
||||
.nf7 = mod->nf7,
|
||||
.nf7 = mod->super.nf7,
|
||||
.malloc = mod->malloc,
|
||||
.data = this,
|
||||
.run = run_single_test_,
|
||||
|
||||
4
main.c
4
main.c
@@ -52,10 +52,10 @@ int main(int argc, char** argv) {
|
||||
// destroy modules
|
||||
for (uint32_t i = 0; i < nf7.mods.n; ++i) {
|
||||
struct nf7_mod* mod = nf7.mods.ptr[i];
|
||||
assert(mod->meta->delete);
|
||||
assert(mod->meta->del);
|
||||
|
||||
nf7util_log_debug("unloading module: %s", mod->meta->name);
|
||||
mod->meta->delete(mod);
|
||||
mod->meta->del(mod);
|
||||
}
|
||||
nf7util_log_info("unloaded all modules");
|
||||
|
||||
|
||||
4
nf7.h
4
nf7.h
@@ -31,6 +31,7 @@ struct nf7 {
|
||||
};
|
||||
|
||||
struct nf7_mod {
|
||||
const struct nf7* nf7;
|
||||
const struct nf7_mod_meta* meta;
|
||||
};
|
||||
|
||||
@@ -39,8 +40,7 @@ struct nf7_mod_meta {
|
||||
const uint8_t* desc;
|
||||
uint32_t ver;
|
||||
|
||||
void (*delete)(struct nf7_mod*);
|
||||
void (*push_lua)(struct nf7_mod*);
|
||||
void (*del)(struct nf7_mod*);
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user