Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update calling-wren-from-c.markdown #1133

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions doc/site/embedding/calling-wren-from-c.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -124,6 +125,10 @@ wrenEnsureSlots(vm, 1);
wrenGetVariable(vm, "main", "GameEngine", 0);
</pre>

***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:
Expand Down