Atom

Configuration and ABI types

Pass a zero-initialized AtomConfig with the desired fields filled in. A null config also takes defaults. Passing the struct copies its configuration. Keep the callback contexts it references valid for every call that can use them, including worker or allocator finalization when applicable. These are host settings.

Fields Behavior
write, write_context Console sink. With no sink, script print raises. The callback returns true if it consumed the indicated bytes.
load_module, release_module, module_context Source loader and optional release callback. For successful loads return source bytes and a canonical, nonempty filename. Buffer and filename remain valid until release. With no loader, quoted file imports are disabled.
load_resource, resource_context Resolves named resources. Return bytes and length, kept valid while Atom copies them. Enables the resource module when selected.
allow_files, allow_network, allow_ffi, allow_process Defaults false. Enable the relevant capability and registration of dependent modules or process members. File imports are separately controlled by the source loader. Grant these capabilities only for code trusted with their effects on the host process.
core_only, modules, module_count Core-only disables automatic module registration. A non-null list filters automatic modules by exact name. A non-null empty list selects none. The host can explicitly register its own modules.
share_loaders_with_workers Defaults false. Opt in only when the source and resource callbacks and their contexts support concurrent calls.
argc, argv UTF-8 argument strings used to initialize os.args. Provide a valid array with argc entries.
jit Requests MIR JIT when built and supported. Defaults false.
instruction_limit, call_limit Instruction budget zero means unlimited. Call depth zero selects the default of 256. Limits are applied to top-level runs and calls, and inherited by workers.
heap_limit Per-VM managed allocation budget in bytes. Zero leaves allocations unmetered. Inherited separately by workers.
allocate_native, free_native, native_memory_context Optional matched allocator pair for ffi.alloc. The allocator must supply malloc-aligned memory. Its context must survive all owned pointers and their finalizers.

AtomValue is a tagged C structure with an AtomType, a numeric representation byte and a union. Inspect the tag before reading the matching union field. Use as.boolean, as.integer, as.unsigned_integer, as.real, or as.character for the immediate representations. Descriptor IDs occupy as.unsigned_integer. Managed objects use as.object. The public tag list is ATOM_NULL, ATOM_BOOL, ATOM_INT, ATOM_UINT, ATOM_FLOAT, ATOM_CHAR, ATOM_STRING, ATOM_ARRAY, ATOM_DICT, ATOM_TABLE, ATOM_RANGE, ATOM_FUNCTION, ATOM_TYPE, ATOM_PACKED, ATOM_MODULE, ATOM_POINTER, ATOM_LIBRARY, ATOM_FILE, ATOM_COROUTINE, ATOM_TASK, ATOM_CHANNEL, ATOM_SOCKET, ATOM_PROCESS, ATOM_DATABASE and ATOM_LAYOUT.

AtomSource contains filename, source and byte length. AtomWrite is bool (*)(void *, const char *, size_t). AtomNative is AtomStatus (*)(AtomVM *, void *, size_t, const AtomValue *, AtomValue *). It receives the VM, registered C context, argument count, borrowed argument array and result slot. On success set the result and return ATOM_OK. For a script exception return atom_error(vm, message). Module and resource loaders return a boolean success result. The release callback receives the source returned by its paired loader. Loader callbacks receive the context from the configuration.