From 040d55907ef9c4f5eb297909fd0772249308771f Mon Sep 17 00:00:00 2001 From: Paolo Mazzon Date: Thu, 5 Jan 2023 23:00:59 -0800 Subject: [PATCH] Update calling-wren-from-c.markdown I added a few tidbits noting that modules must first be loaded with `wrenInterpret()` before they are visible to the VM as elegantly into the docs as I could. --- doc/site/embedding/calling-wren-from-c.markdown | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/doc/site/embedding/calling-wren-from-c.markdown b/doc/site/embedding/calling-wren-from-c.markdown index a780f48ee..8a21ba966 100644 --- a/doc/site/embedding/calling-wren-from-c.markdown +++ b/doc/site/embedding/calling-wren-from-c.markdown @@ -9,10 +9,11 @@ It's also not an effective way to communicate. You can't pass arguments to Wren—at least, not without doing something nasty like converting them to literals in a string of source code—and you can't get a result value back. -`wrenInterpret()` is great for loading code into the VM, but it's not the best -way to execute code that's already been loaded. What we want to do is invoke -some already compiled chunk of code. Since Wren is an object-oriented language, -"chunk of code" means a [method][], not a [function][]. +`wrenInterpret()` is great for loading code into the VM (and the only way to +load code into the VM), but it's not the best way to execute code that's +already been loaded. What we want to do is invoke some already compiled chunk +of code. Since Wren is an object-oriented language, "chunk of code" means a +[method][], not a [function][]. [method]: ../method-calls.html [function]: ../functions.html @@ -124,6 +125,10 @@ wrenEnsureSlots(vm, 1); wrenGetVariable(vm, "main", "GameEngine", 0); +***Note:*** We also need to make sure the method we are trying to find with +`wrenGetVariable()` has already been imported into the VM through +`wrenInterpret()`. + We could do this every time we call `update()`, but, again, that's kind of slow because we're looking up "GameEngine" by name each time. A faster solution is to create a handle to the class once and use it each time: