Load and use functions from dynamic libraries (.so, .dll) in your Talon games
The embed module allows you to extend Talon with custom C/C++ functions by loading them from shared libraries. This enables you to integrate existing native code or write performance-critical functionality in C.
import "embed" for Loadclass C { foreign static add(a, b)}Load.foreignFunction("C.add(_,_)", "add.dll", "wren_c_embed_add")// Now you can use itvar result = C.add(5, 3)System.print("5 + 3 = %(result)") // Prints: 5 + 3 = 8
// Get parameters (slots start at 1)double num = wrenGetSlotDouble(vm, 1);const char* str = wrenGetSlotString(vm, 1);bool flag = wrenGetSlotBool(vm, 1);
void wren_c_embed_multiply(WrenVM* vm) { double x = wrenGetSlotDouble(vm, 1); double y = wrenGetSlotDouble(vm, 2); double z = wrenGetSlotDouble(vm, 3); wrenSetSlotDouble(vm, 0, x * y * z);}
class Math { foreign static multiply(x, y, z)}Load.foreignFunction("Math.multiply(_,_,_)", "math.dll", "wren_c_embed_multiply")var result = Math.multiply(2, 3, 4) // Returns 24
Place the DLL in the same directory as your executable or Wren script.
The embed system only works when running Talon natively (not in WASM). WebAssembly builds cannot load dynamic libraries due to browser security restrictions.