Introduction to the C API
The C API is a low level library, designed to allow anyone to write a worker in any language which can understand a C API, including dynamic languages such as Lua and Python. Like any other worker, a C worker can subscribe to information for a part of a SpatialOS simulated world, visualize it, and perform some computation on behalf of the simulated world.
Unlike the C++, C# and Java SDKs, the C API does not provide any generated code. Instead, it exposes serialization functions to read and write:
- component data
- component updates
- command requests and responses.
This requires substantially more work to get started, because you will likely need to implement code generation yourself using custom codegen. However, this approach enables far more flexibility. For example, if you use the C API to create a worker in a dynamic language, you could write fully dynamic serialization code which uses reflection (perhaps after being validated using some custom generated code based off the project’s schema). You could also generate serialization code directly in the dynamic language, which can then be hot reloaded without restarting the worker.
In addition to connecting to a simulation, the API also includes methods to load and save snapshots of the entire simulation from and to a file. This lets you write tooling to modify the state of the simulation offline, or to programmatically create the initial point of a simulation.