Skip to content

Commit

Permalink
Improve run-time API documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
fwsGonzo committed Nov 30, 2024
1 parent 1ebd2ac commit 87d85f2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
10 changes: 10 additions & 0 deletions docs/godot_docs/cppexamples.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,16 @@ CharacterBody2D player("%Player");
const bool f = player.is_on_floor();
```
The API is generated from the static function [Sandbox.generate_api](../godot_intro/sandbox.md#sandbox-api-reference):
```py
var api = Sandbox.generate_api("cpp")
var fa = FileAccess.open("generated_api.hpp", FileAccess.WRITE)
fa.store_string(api)
fa.close()
```

The C++ API will look for `generated_api.hpp`, and if found, will automatically include it.

:::note

In practice you can write code just like GDScript. Even classes loaded at run-time should be accessible with auto-complete.
Expand Down
9 changes: 6 additions & 3 deletions docs/godot_intro/sandbox.md
Original file line number Diff line number Diff line change
Expand Up @@ -389,8 +389,11 @@ class Sandbox : public Node {
/// @return True if binary translation is loaded, false otherwise.
bool is_binary_translated() const;

/// @brief Generate the C++ API to a String, based on current Godot version and loaded extensions.
/// @return The generated C++ API.
static String generate_api(String language = "cpp", String header_extra = "");
/// @brief Generate the run-time API for the guest program, by iterating through all loaded classes.
/// @param language The language to generate the API for.
/// @param header_extra Extra header code to add to the generated API.
/// @param use_argument_names If true, use argument names with default values in the generated API. Increases the size of the generated API and the compilation time.
/// @return The generated API code as a string.
static String generate_api(String language = "cpp", String header_extra = "", bool use_argument_names = false);
};
```

0 comments on commit 87d85f2

Please sign in to comment.