# Nucleation Examples & Documentation
This directory contains comprehensive documentation and working code examples for all Nucleation language bindings.
## ๐ File Structure
```
examples/
โโโ README.md # This file
โโโ rust.md # Rust API documentation
โโโ rust_example.rs # Complete Rust example code
โโโ wasm.md # JavaScript/WASM API documentation
โโโ wasm_example.js # Complete JavaScript/WASM example code
โโโ python.md # Python API documentation
โโโ python_example.py # Complete Python example code
โโโ ffi.md # C/FFI API documentation
โโโ ffi_example.c # Complete C/FFI example code
โโโ blockpedia_showcase.rs # Blockpedia integration example (Rust only)
```
## ๐ Documentation vs Examples
Each binding has **two types of resources**:
### 1. ๐ API Documentation (`.md` files)
- **Purpose**: Reference documentation for all available APIs
- **Format**: Structured tables with method signatures and descriptions
- **Usage**: Quick lookup for specific functions, parameters, and return types
- **Examples**: [`rust.md`](rust.md), [`wasm.md`](wasm.md), [`python.md`](python.md), [`ffi.md`](ffi.md)
### 2. ๐ง Working Code Examples (source files)
- **Purpose**: Complete, runnable examples demonstrating real-world usage
- **Format**: Full source code with comments and multiple usage patterns
- **Usage**: Copy-paste starting points, learning comprehensive workflows
- **Examples**: [`rust_example.rs`](rust_example.rs), [`wasm_example.js`](wasm_example.js), [`python_example.py`](python_example.py), [`ffi_example.c`](ffi_example.c)
## ๐ Running the Examples
### Rust Example
```bash
cargo run --example rust_example
# or
rustc --extern nucleation examples/rust_example.rs && ./rust_example
```
### JavaScript/WASM Example
```bash
# Node.js
node examples/wasm_example.js
# Browser
# Serve the example with a local HTTP server
npx serve . --cors
# Open browser to http://localhost:3000/examples/wasm_example.js
```
### Python Example
```bash
# First install nucleation
pip install nucleation
# or build locally: maturin develop --features python
python examples/python_example.py
```
### C/FFI Example
```bash
# First build the FFI library
cargo build --release --features ffi
# Compile the example
gcc -o ffi_example examples/ffi_example.c \
-L./target/release -lnucleation \
-lpthread -ldl -lm
# Run (Linux/macOS)
LD_LIBRARY_PATH=./target/release ./ffi_example
# Run (Windows)
# Add target/release to PATH or copy nucleation.dll to current directory
./ffi_example.exe
```
## ๐งช What Each Example Demonstrates
All examples cover the same comprehensive feature set:
- โ
**Basic Usage**: Creating schematics, adding blocks
- โ
**BlockState Management**: Working with block properties
- โ
**File Operations**: Loading/saving different schematic formats
- โ
**Advanced Features**: Querying blocks, ASCII visualization, debug info
- โ
**Chunk Operations**: Working with chunked data and different strategies
- โ
**Region Copying**: Copying sections between schematics
- โ
**Error Handling**: Proper error management patterns
- โ
**Memory Management**: Language-specific resource cleanup
## ๐ Type Definitions
Generated type definitions are available for type-safe development:
- **TypeScript**: [`../pkg/nucleation.d.ts`](../pkg/nucleation.d.ts) (auto-generated by wasm-pack)
- **Python**: [`../python-stubs/nucleation.pyi`](../python-stubs/nucleation.pyi) (auto-generated from API definition)
- **C**: [`../include/nucleation.h`](../include/nucleation.h) (auto-generated from API definition)
- **Rust**: Native Rust documentation via `cargo doc`
## ๐ค Auto-Generation
All binding documentation and type definitions are **automatically generated** from the single source of truth in [`../src/api_definition.rs`](../src/api_definition.rs).
To regenerate all bindings:
```bash
cargo run --bin generate-bindings
```
This ensures **feature parity** and **consistency** across all language bindings.
## ๐ Feature Matrix
| Core Schematic API | โ
| โ
| โ
| โ
|
| File I/O | โ
| โ
| โ
| โ
|
| Block Management | โ
| โ
| โ
| โ
|
| Chunk Operations | โ
| โ
| โ
| โ ๏ธ Limited |
| Region Copying | โ
| โ
| โ
| โ ๏ธ Limited |
| Blockpedia Integration | โ
| โ | โ | โ |
| Memory Safety | โ
| โ
| โ
| โ ๏ธ Manual |
**Note**: Blockpedia integration (color analysis, block transformations) is only available on native Rust targets due to WASM compatibility constraints.
## ๐ก Getting Help
1. **Quick Reference**: Check the `.md` documentation files
2. **Working Examples**: Run the example source files
3. **Type Safety**: Use the generated type definitions
4. **API Report**: See [`../API_REPORT.md`](../API_REPORT.md) for a complete API overview
5. **Issues**: Report problems on [GitHub Issues](https://github.com/Schem-at/Nucleation/issues)
Happy building! ๐