Skip to content

Commit

Permalink
Add basic docs
Browse files Browse the repository at this point in the history
  • Loading branch information
vdrg committed Nov 25, 2024
1 parent 2312bdb commit e6fd25a
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions docs/pages/world/systems.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,43 @@ If your `System` needs run both from the root namespace and from other namespace

</details>

#### System Libraries

<Callout type="warning" emoji="⚠️">
This is an experimental feature and is not recommended for production use yet. Its API is expected to change in the
future.
</Callout>

By setting the `generateSystemLibraries` codegen setting to true in your MUD config, the `worldgen` CLI will automatically generate a Solidity library for each system in your project. This feature simplifies inter-system communication by providing a convenient way of calling functions between systems.

Each generated library defines and exports a custom user-defined type that includes all the functions defined in the corresponding system. Internally, these system libraries utilize the World's `call` and `callFrom` methods to execute the actual system contracts.

```solidity filename="MySystem.sol"
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.24;
import { System } from "@latticexyz/world/src/System.sol";
// Library generated for MoveSystem,
import { moveSystem } from "./codegen/libraries/MoveSystemLib.sol";
contract MySystem is System {
function someAction(uint256 x, uint256 y) external {
// All functions defined in the MoveSystem system are available globally for the exported `moveSystem` value
moveSystem.move(x, y);
// You can also use delegations (if they exist) by using `callFrom`
moveSystem.callFrom(_msgSender()).move(x, y);
// If MySystem is a root system, you need to use `callAsRoot`
moveSystem.callAsRoot().move(x, y);
// If MySystem is a root system, it can call other systems on behalf of any address with `callAsRootFrom`
moveSystem.callAsRootFrom(_msgSender()).move(x, y);
}
}
```

## Registering systems

For a `System` to be callable from a `World` it has to be [registered](https://github.com/latticexyz/mud/blob/main/packages/world/src/modules/init/implementations/WorldRegistrationSystem.sol#L115-L178).
Expand Down

0 comments on commit e6fd25a

Please sign in to comment.