Skip to content

Commit bee6092

Browse files
committed
docs for _NORES variant
1 parent 6e95702 commit bee6092

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

mods/dependencies.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ description: How to install dependencies to Geode mods
66

77
Geode provides utilities for mods to depend on other mods, to make sharing code easy.
88

9-
Note that Geode **only manages dependencies that are mods**. Normal C++ dependencies, like a JSON parsing library, ZIP library, or some networking utilities, **should just be installed like they are in any other C++ project**. Use CPM, Git submodules, copy the code to your project, whatever you prefer. If the library is dynamic, include the `.dll` with your mod through the `files` key in `resources`.
9+
Note that Geode **only manages dependencies that are mods**. Normal C++ dependencies, like a JSON parsing library, ZIP library, or some networking utilities, **should just be installed like they are in any other C++ project**. Use CPM, Git submodules, copy the code to your project, whatever you prefer. If the library is dynamic, include the `.dll` with your mod through the `files` key in `resources`.
1010

1111
However, sometimes you want to depend on code that can't just be used as a normal library; for example, **custom keybinds**. Geode does not provide any custom keybinds utilities out-of-the-box, so you need to use a library. However, it would not make much sense if every mod bundled their own incompatible systems for dealing with custom keybinds. Instead, there should be one mod that just adds the functionality, and then other mods can depend on that mod and call its functions to add keybinds.
1212

@@ -160,6 +160,9 @@ Two versions of the macro are available:
160160
#pragma once
161161

162162
#include <Geode/loader/Dispatch.hpp>
163+
#ifdef MY_MOD_ID
164+
#undef MY_MOD_ID
165+
#endif
163166
// You must **manually** declare the mod id, as macros like GEODE_MOD_ID will not
164167
// behave correctly to other mods using your api.
165168
#define MY_MOD_ID "dev.my-api"
@@ -168,6 +171,13 @@ namespace api {
168171
// Important: The function must be declared inline, and return a geode::Result,
169172
// as it can fail if the api is not available.
170173
inline geode::Result<int> addNumbers(int a, int b) GEODE_EVENT_EXPORT(&addNumbers, (a, b));
174+
175+
// Alternatively, use the `_NORES` variant of the macro, which will return a default value
176+
// if the api isn't available. Ex: this will return 0 if the mod is unavailable
177+
inline int factorial(int x) GEODE_EVENT_EXPORT_NORES(&factorial, (x));
178+
179+
// It also works with void:
180+
inline void doSomething() GEODE_EVENT_EXPORT_NORES(&doSomething, ());
171181
}
172182
```
173183
@@ -181,4 +191,12 @@ Then, in **one** of your source files, you must define the exported functions:
181191
Result<int> api::addNumbers(int a, int b) {
182192
return Ok(a + b);
183193
}
194+
195+
int api::factorial(int x) {
196+
return 42;
197+
}
198+
199+
void api::doSomething() {
200+
// ...
201+
}
184202
```

0 commit comments

Comments
 (0)