fixed 2 bugs

This commit is contained in:
2026-02-05 11:44:24 +01:00
parent e5095f4624
commit 4a2a60990b
2 changed files with 30 additions and 5 deletions

View File

@@ -27,6 +27,24 @@ static nn_Exit sandbox_handler(nn_ComponentRequest *req) {
return NN_OK;
}
static nn_Exit sandbox_arch(nn_ArchitectureRequest *req) {
nn_Computer *c = req->computer;
switch(req->action) {
case NN_ARCH_INIT:
return NN_OK;
case NN_ARCH_DEINIT:
return NN_OK;
case NN_ARCH_FREEMEM:
req->freeMemory = 0;
return NN_OK;
case NN_ARCH_TICK:
nn_pushstring(c, "Hello from component call");
nn_call(c, "sandbox", "log");
return NN_OK;
}
return NN_OK;
}
int main() {
nn_Context ctx;
nn_initContext(&ctx);
@@ -34,6 +52,12 @@ int main() {
// create the universe
nn_Universe *u = nn_createUniverse(&ctx);
nn_Architecture arch = {
.name = "Sandbox test",
.state = NULL,
.handler = sandbox_arch,
};
nn_ComponentMethod sandboxMethods[] = {
{"log", "log(msg: string) - Log to stdout", true},
{NULL},
@@ -42,10 +66,9 @@ int main() {
nn_Computer *c = nn_createComputer(u, NULL, "computer0", 8 * NN_MiB, 256, 256);
nn_addComponent(c, ctype, "sandbox", -1, NULL);
nn_setArchitecture(c, &arch);
nn_pushstring(c, "Hello from component call");
nn_call(c, "sandbox", "log");
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");