API Conventions
中文 · User guide
This page is maintained by hand; the Chinese documentation is authoritative.
Modules and objects
Script constructors live in the global eve table. Constructors such as eve.Physics() and eve.Audio() create module objects. Their factories create helper objects such as worlds, bodies and audio sources. Call a method on its owning object, not on the module merely because it appears in the same guide.
The startup environment creates common global instances. Explicit project module lists can limit them. Reuse the injected instances when appropriate instead of recreating long-lived modules each frame.
Where to look up an API
The handbook explains workflows, examples, ownership and failure handling. Method lists are not copied into it.
- C++ declarations and contracts: the generated Doxygen reference, especially
@param,@returnand@throws. - Callable EveScript methods: your SDK's
share/eve/ai/eve-api.json, editor completion/hover, or MCPeve_api_search/eve_api_get. - Source checkout: bindings in
expose(...)/addFunc/addVar, script-injected classes, and the module's tests. To generate the script catalog locally, usepython3 scripts/generate_binding_contracts.py --json-output eve-api.json.
An exposed C++ public method is not automatically an EveScript method. C++ default arguments are not automatically script defaults. Use positional arguments when the binding signature is unknown or ambiguous.
Errors and results
Read each method's documented contract before calling it.
- Programming mistakes and failed preconditions, such as invalid choices, out-of-range indices or uninitialized backends, throw exceptions. Script bindings report them as Squirrel exceptions. Fix them rather than silently swallowing them.
- Recoverable failures may return
false,nullor a structured Result, depending on the API. Always check the documented return value. - For Result tables, check
result.okbefore usingresult.value. Inspectstatus.summary/diagnosticson failure. Do not discard a Result; explicitly ignored results need a reason.
For a recoverable resource-loading exception:
Ownership and lifecycle
- Keep worlds, textures, sources, emitters and scene hosts in persistent game state or entity components for as long as they are used.
- Create and load resources during initialization. Do not repeatedly load from disk in
eve_render(). update(dt)normally takes seconds. Check the module's coordinate contract: 2D physics commonly uses pixel coordinates, while 3D physics uses meters.- Consume input and network events during update; submit drawing during render.
- Top-level code runs again on hot reload. Use
persistfor state that must survive and migrate changed data layouts explicitly ineve_reload().