Added onLoad() lifecycle function

This commit is contained in:
2023-03-03 00:50:45 +11:00
parent 00587e91b2
commit 4965cd492d
11 changed files with 90 additions and 64 deletions

View File

@@ -50,14 +50,14 @@ static int nativeLoadNode(Toy_Interpreter* interpreter, Toy_LiteralArray* argume
Box_EngineNode* node = TOY_ALLOCATE(Box_EngineNode, 1);
//BUGFIX: make an inner-interpreter
//BUGFIX: make an -interpreter
Toy_Interpreter inner;
//init the inner interpreter manually
Toy_initLiteralArray(&inner.literalCache);
Toy_initLiteralArray(&inner.stack);
inner.hooks = interpreter->hooks;
inner.scope = Toy_pushScope(NULL);
inner.scope = Toy_pushScope(interpreter->scope);
inner.bytecode = tb;
inner.length = size;
inner.count = 0;
@@ -70,6 +70,9 @@ static int nativeLoadNode(Toy_Interpreter* interpreter, Toy_LiteralArray* argume
Box_initEngineNode(node, &inner, tb, size);
//immediately call onLoad() after running the script - for loading other nodes
Box_callEngineNode(node, &engine.interpreter, "onLoad", NULL);
// return the node
Toy_Literal nodeLiteral = TOY_TO_OPAQUE_LITERAL(node, node->tag);
Toy_pushLiteralArray(&interpreter->stack, nodeLiteral);