components
This commit is contained in:
@@ -3,6 +3,22 @@
|
||||
// it is simply just to test stuff and showcase the API.
|
||||
|
||||
#include "neonucleus.h"
|
||||
#include <stdio.h>
|
||||
|
||||
static nn_Exit sandbox_handler(nn_ComponentRequest *req) {
|
||||
switch(req->action) {
|
||||
case NN_COMP_INIT:
|
||||
return NN_OK;
|
||||
case NN_COMP_DEINIT:
|
||||
return NN_OK;
|
||||
case NN_COMP_CALL:
|
||||
return NN_OK;
|
||||
case NN_COMP_ENABLED:
|
||||
req->methodEnabled = true; // all methods always enabled
|
||||
return NN_OK;
|
||||
}
|
||||
return NN_OK;
|
||||
}
|
||||
|
||||
int main() {
|
||||
nn_Context ctx;
|
||||
@@ -15,13 +31,19 @@ int main() {
|
||||
{"log", "log(msg: string) - Log to stdout", true},
|
||||
NULL,
|
||||
};
|
||||
nn_ComponentType *ctype = nn_createComponentType(u, "sandbox", NULL, sandboxMethods, NULL);
|
||||
nn_ComponentType *ctype = nn_createComponentType(u, "sandbox", NULL, sandboxMethods, sandbox_handler);
|
||||
|
||||
nn_Computer *c = nn_createComputer(u, NULL, "computer0", 8 * NN_MiB, 256, 256);
|
||||
|
||||
nn_addComponent(c, ctype, "sandbox", -1, NULL);
|
||||
|
||||
printf("Component added: %s\n", nn_hasComponent(c, "sandbox") ? "TRUE" : "FALSE");
|
||||
printf("Method active: %s\n", nn_hasMethod(c, "sandbox", "log") ? "TRUE" : "FALSE");
|
||||
printf("Incorrect method active: %s\n", nn_hasMethod(c, "sandbox", "notlog") ? "TRUE" : "FALSE");
|
||||
|
||||
cleanup:;
|
||||
nn_destroyComponentType(ctype);
|
||||
nn_destroyComputer(c);
|
||||
nn_destroyComponentType(ctype);
|
||||
// rip the universe
|
||||
nn_destroyUniverse(u);
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user