Moved all docs from ./docs/ to ./web/documentation/ to be available on the website. No code changes. (0.40.5)
This commit is contained in:
parent
8f2847abfb
commit
567fa73796
224 changed files with 4584 additions and 1139 deletions
55
web/documentation/embedding.md
Normal file
55
web/documentation/embedding.md
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
---
|
||||
layout: page
|
||||
published: true
|
||||
noToc: true
|
||||
noComments: false
|
||||
noDate: false
|
||||
title: Fun - Embedding Fun
|
||||
subtitle: Embedding the VM from C/Rust, lifecycle, and host integration tips.
|
||||
description: Embedding the VM from C/Rust, lifecycle, and host integration tips.
|
||||
permalink: /documentation/embedding/
|
||||
lang: en
|
||||
tags:
|
||||
- documentation
|
||||
- handbook
|
||||
- installation
|
||||
- usage
|
||||
- introduction
|
||||
- help
|
||||
- guide
|
||||
- howto
|
||||
- docs
|
||||
- specifications
|
||||
- specs
|
||||
- repl
|
||||
---
|
||||
|
||||
# Embedding Fun
|
||||
|
||||
This guide outlines how to embed the Fun VM in a host application and extend it from C/Rust.
|
||||
|
||||
## Overview
|
||||
- The VM is implemented in C (see [src/vm](../src/vm/)).
|
||||
- Optional Rust-based opcodes can be enabled via `FUN_WITH_RUST` (see [rust.md](./rust/)).
|
||||
|
||||
## Embedding from C
|
||||
While the exact API surface may evolve, a typical embedding flow looks like:
|
||||
1. Initialize the VM/runtime and allocate a context.
|
||||
2. Load/compile Fun source or bytecode.
|
||||
3. Push arguments or set globals as needed.
|
||||
4. Execute entry function or script body.
|
||||
5. Retrieve results and clean up.
|
||||
|
||||
See [src/vm/core](../src/vm/core/) and related headers for public entry points and value types.
|
||||
|
||||
### Hosting considerations
|
||||
- Threading: share VM state cautiously or create one VM per thread.
|
||||
- Memory: clarify ownership of strings/buffers crossing the boundary.
|
||||
- Errors: propagate parse/runtime errors back to the host with useful messages.
|
||||
|
||||
## Extending with Rust
|
||||
When `FUN_WITH_RUST=ON`, a Rust static library from [`src/rust/`](../src/rust/) is built and linked. You can:
|
||||
- Implement new opcodes/functions in Rust.
|
||||
- Expose a C ABI for the VM to call into.
|
||||
|
||||
See [rust.md](./rust/) for details and example code.
|
||||
Loading…
Add table
Add a link
Reference in a new issue