Worker SDK in C
The Worker SDK in C is an implementation of the Worker SDK. It 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 C++, C# and Java, the Worker SDK in C 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 Worker SDK in C 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.
Using the C example project
The C example project is a fairly minimal example of project structure and build configuration for workers using the Worker SDK in C. We recommend you use it as a starting point, along with Setup and installation and Building a worker.