1
- # godot_headers
2
- #### ` GDNative / NativeScript `
1
+ # godot-headers
3
2
4
- > ` GDNative ` enables the use of dynamically linked libraries inside of [ ** Godot** ] ( https://github.com/godotengine/godot ) .
3
+ This repository contains C headers for
4
+ [ ** Godot Engine** ] ( https://github.com/godotengine/godot ) 's * GDNative* API,
5
+ which can be used to write * NativeScripts* .
6
+
7
+ > ` GDNative ` enables the use of dynamically linked libraries inside of
8
+ > [ ** Godot** ] ( https://github.com/godotengine/godot ) .
5
9
6
10
> ` NativeScript ` uses GDNative to implement scripts backed by native code.
7
11
8
- - [ ** Branches** ] ( #branches )
9
- - [ ** Getting Started** ] ( #getting-started )
10
- - [ ** FAQ** ] ( #faq )
12
+ - [ ** Versioning** ] ( #versioning )
13
+ - [ ** Getting Started** ] ( #getting-started )
14
+ - [ ** FAQ** ] ( #faq )
15
+ - [ ** Updating Headers** ] ( #updating-headers )
16
+
17
+ ## Versioning
11
18
12
- ## Branches
19
+ This repositories follows the same branch versioning as the main [ Godot Engine
20
+ repository] ( https://github.com/godotengine/godot ) :
13
21
14
- We maintain branches on this repo that relate directly to the main builds of Godot.
15
- Make sure you use the correct branch for the version of Godot you are using!
22
+ - ` master ` tracks the current development branch. As this is a moving target,
23
+ the headers in this repository may not always be fully in sync with upstream.
24
+ See [ ** Updating Headers** ] ( #updating-headers ) if you need to bring
25
+ them up to date.
26
+ - ` 3.x ` tracks the development of the next 3.x minor release. Like ` master ` , it
27
+ might not always be fully up-to-date with upstream.
28
+ - Other versioned branches (e.g. ` 3.3 ` , ` 3.2 ` ) track the latest stable release
29
+ in the corresponding branch.
16
30
17
- | Branch | Version of Godot |
18
- | --- | --- |
19
- | [ master ] ( https://github.com/GodotNativeTools/godot_headers ) | Godot master |
20
- | [ 3.2 ] ( https://github.com/GodotNativeTools/godot_headers/tree/3.2 ) | Godot 3.2.x |
21
- | [ 3.1 ] ( https://github.com/GodotNativeTools/godot_headers/tree/3.1 ) | Godot 3.1.x |
22
- | [ 3.0 ] ( https://github.com/GodotNativeTools/godot_headers/tree/3.0 ) | Godot 3.0.x |
31
+ Stable releases are also tagged on this repository:
32
+ [ ** Tags ** ] ( https://github.com/godotengine/godot-headers/tags ) .
33
+
34
+ ** For any project built against a stable release of Godot, we recommend using
35
+ this repository as a Git submodule, checking out the specific tag matching your
36
+ Godot version. **
23
37
24
38
## Getting Started
25
39
26
- | ** Build latest version of Godot** | [ ** GitHub** ] ( https://github.com/godotengine/godot ) | [ ** Docs** ] ( https://godot.readthedocs.io /en/latest/development/compiling/index.html ) |
40
+ | ** Build latest version of Godot** | [ ** GitHub** ] ( https://github.com/godotengine/godot ) | [ ** Docs** ] ( https://docs.godotengine.org /en/latest/development/compiling/index.html ) |
27
41
| --- | --- | --- |
28
42
29
- ### Clone godot_headers into Library
43
+ ### Clone ` godot-headers ` into Library
30
44
31
- Clone ` godot_headers ` under ` SimpleLibrary/ `
45
+ Clone ` godot-headers ` under ` SimpleLibrary/ `
32
46
33
47
``` bash
34
48
cd SimpleLibrary
35
- git clone https://github.com/GodotNativeTools/godot_headers
49
+ git clone https://github.com/godotengine/godot-headers
36
50
```
37
51
38
- > Note that the master branch of this repository contains the header for the latest Godot master. If you want to build GDNative modules for older versions of Godot add ` -b <version> ` to the git clone command above. i.e. ` git clone https://github.com/GodotNativeTools/godot_headers -b 3.0 ` will retrieve headers compatible with Godot 3.0.
39
-
40
- > With the exception of a breaking change in the ARVR module between 3.0 and 3.1, GDNative plugins written for an older version of Godot will work in newer versions.
52
+ Note that the master branch of this repository contains the headers for the
53
+ latest Godot ` master ` branch. See [ ** Versioning** ] ( #versioning ) for details.
54
+ You can use ` -b <version> ` to the above Git clone command to retrieve a specific
55
+ branch or tag (e.g. ` -b 3.x ` or ` -b godot-3.3.3-stable ` ).
41
56
42
57
``` bash
43
58
[SimpleLibrary]
@@ -47,7 +62,7 @@ git clone https://github.com/GodotNativeTools/godot_headers
47
62
48
63
### Create Script
49
64
50
- Create ` test.c ` under ` SimpleLibrary/src/ `
65
+ Create ` test.c ` under ` SimpleLibrary/src/ ` .
51
66
52
67
<details >
53
68
@@ -58,22 +73,22 @@ Create `test.c` under `SimpleLibrary/src/`
58
73
#include < stdio.h>
59
74
60
75
void *test_constructor (godot_object * obj, void * method_data) {
61
- printf("test.constructor()\n");
62
- return 0;
76
+ printf("test.constructor()\n");
77
+ return 0;
63
78
}
64
79
65
80
void test_destructor(godot_object * obj, void * method_data, void * user_data) {
66
- printf("test.destructor()\n");
81
+ printf("test.destructor()\n");
67
82
}
68
83
69
84
/** func _ ready() ** /
70
85
godot_variant test_ready(godot_object * obj, void * method_data, void * user_data, int num_args, godot_variant ** args) {
71
- godot_variant ret;
72
- godot_variant_new_nil(&ret);
86
+ godot_variant ret;
87
+ godot_variant_new_nil(&ret);
73
88
74
- printf("_ready()\n");
89
+ printf("_ready()\n");
75
90
76
- return ret;
91
+ return ret;
77
92
}
78
93
79
94
/** Library entry point ** /
@@ -90,64 +105,64 @@ void GDN_EXPORT godot_nativescript_init(void *desc) {
90
105
91
106
godot_instance_create_func create_func = {
92
107
.create_func = &test_constructor,
93
- .method_data = 0,
94
- .free_func = 0
95
- };
96
-
97
- godot_instance_destroy_func destroy_func = {
98
- .destroy_func = &test_destructor,
99
- .method_data = 0,
100
- .free_func = 0
101
- };
102
-
103
- godot_nativescript_register_class(desc, "SimpleClass", "Node", create_func, destroy_func);
104
-
105
- {
106
- godot_instance_method method = {
107
- .method = &test_ready,
108
- .method_data = 0,
109
- .free_func = 0
110
- };
111
-
112
- godot_method_attributes attr = {
113
- .rpc_type = GODOT_METHOD_RPC_MODE_DISABLED
114
- };
115
-
116
- godot_nativescript_register_method(desc, "SimpleClass", "_ready", attr, method);
117
- }
108
+ .method_data = 0,
109
+ .free_func = 0
110
+ };
111
+
112
+ godot_instance_destroy_func destroy_func = {
113
+ .destroy_func = &test_destructor,
114
+ .method_data = 0,
115
+ .free_func = 0
116
+ };
117
+
118
+ godot_nativescript_register_class(desc, "SimpleClass", "Node", create_func, destroy_func);
119
+
120
+ {
121
+ godot_instance_method method = {
122
+ .method = &test_ready,
123
+ .method_data = 0,
124
+ .free_func = 0
125
+ };
126
+
127
+ godot_method_attributes attr = {
128
+ .rpc_type = GODOT_METHOD_RPC_MODE_DISABLED
129
+ };
130
+
131
+ godot_nativescript_register_method(desc, "SimpleClass", "_ready", attr, method);
132
+ }
118
133
}
119
134
120
135
godot_variant GDN_EXPORT some_test_procedure(void * data, godot_array * args) {
121
- godot_variant ret;
122
- godot_variant_new_int(&ret, 42);
136
+ godot_variant ret;
137
+ godot_variant_new_int(&ret, 42);
123
138
124
- godot_string s;
125
- godot_string_new_unicode_data (&s, L"Hello World", 11);
126
- godot_print(&s);
139
+ godot_string s;
140
+ godot_string_new_with_wide_string (&s, L"Hello World", 11);
141
+ godot_print(&s);
127
142
128
- godot_string_destroy(&s);
143
+ godot_string_destroy(&s);
129
144
130
- return ret;
145
+ return ret;
131
146
}
132
147
```
133
148
134
149
</details>
135
150
136
- ` Expand details for example code.`
151
+ Expand *Details* for example code.
137
152
138
153
### Compile Library
139
154
140
155
On Linux:
141
156
142
157
```bash
143
- clang -g -fPIC -std=c99 - c src/test.c -I/path/to/godot/headers/ -o src/test.os
158
+ clang -g -fPIC -c src/test.c -I/path/to/godot/headers/ -o src/test.os
144
159
clang -g -shared src/test.os -o lib/test.so
145
160
```
146
161
147
162
On MacOS:
148
163
149
164
``` bash
150
- clang -g -fPIC -std=c99 - c src/test.c -I/path/to/godot/headers/ -o src/test.os
165
+ clang -g -fPIC -c src/test.c -I/path/to/godot/headers/ -o src/test.os
151
166
clang -g -shared -framework Cocoa -Wl,-undefined,dynamic_lookup src/test.os -o lib/test.dylib
152
167
```
153
168
@@ -158,9 +173,9 @@ clang -g -shared -framework Cocoa -Wl,-undefined,dynamic_lookup src/test.os -o l
158
173
The GDNativeLibrary resource contains links to the libraries for each platform.
159
174
160
175
1 . Create a new resource in memory and edit it.
161
- 1 . Select ` Resource > GDNativeLibrary ` .
162
- 1 . Set the library file for your platform inside the inspector.
163
- 1 . Save the edited resource as a ` .tres `
176
+ 2 . Select ` Resource > GDNativeLibrary ` .
177
+ 3 . Set the library file for your platform inside the inspector.
178
+ 4 . Save the edited resource as a ` .tres `
164
179
165
180
<details >
166
181
@@ -174,33 +189,33 @@ The GDNativeLibrary resource contains links to the libraries for each platform.
174
189
175
190
</details >
176
191
177
- ` Expand details for screenshots. `
192
+ Expand * Details * for screenshots.
178
193
179
194
### Using GDNativeLibrary in GDScript
180
195
181
196
``` gdscript
182
197
extends Node
183
198
184
199
func _ready():
185
- var gdn = GDNative.new()
186
- gdn.library = load("res://lib/libtest.tres")
200
+ var gdn = GDNative.new()
201
+ gdn.library = load("res://lib/libtest.tres")
187
202
188
- gdn.initialize()
203
+ gdn.initialize()
189
204
190
- var res = gdn.call_native("standard_varcall", "some_test_procedure", [])
205
+ var res = gdn.call_native("standard_varcall", "some_test_procedure", [])
191
206
192
- print("result: ", res)
207
+ print("result: ", res)
193
208
194
- gdn.terminate()
209
+ gdn.terminate()
195
210
```
196
211
197
212
### Attaching GDNativeLibrary to a Node
198
213
199
214
1 . Attach a new script to a node.
200
- 1 . In the pop-up dialog, choose NativeScript in the ` Language ` menu.
201
- 1 . Enable built-in script, or create a ` .gdn ` file, which only contains a name.
202
- 1 . Specify the ` Class Name ` .
203
- 1 . Press ` Create ` .
215
+ 2 . In the pop-up dialog, choose NativeScript in the ` Language ` menu.
216
+ 3 . Enable built-in script, or create a ` .gdn ` file, which only contains a name.
217
+ 4 . Specify the ` Class Name ` .
218
+ 5 . Press ` Create ` .
204
219
205
220
The GDNativeLibrary field in a NativeScript is empty by default.
206
221
@@ -213,7 +228,7 @@ The GDNativeLibrary field in a NativeScript is empty by default.
213
228
214
229
</details >
215
230
216
- ` Expand details for screenshots. `
231
+ Expand * Details * for screenshots.
217
232
218
233
## FAQ
219
234
@@ -227,8 +242,8 @@ use of GDNative to implement scripts backed by native code.
227
242
228
243
** Which languages are binding as a NativeScript?**
229
244
230
- [ ** C++** ] ( https://github.com/GodotNativeTools/cpp_bindings ) ,
231
- [ ** D** ] ( https://github.com/GodotNativeTools/d_bindings ) ,
245
+ [ ** C++** ] ( https://github.com/godotengine/godot-cpp ) ,
246
+ [ ** D** ] ( https://github.com/godot-d/godot-d ) ,
232
247
[ ** Nim** ] ( https://github.com/pragmagic/godot-nim )
233
248
234
249
** Can you debug NativeScripts?**
@@ -243,5 +258,25 @@ You can! ✨
243
258
** What is the reason behind the name "GDNative"?**
244
259
245
260
GDNative was originally named "cscript" because it exposes a C API, but people
246
- mistook a relation to C#, which is sometimes abbreviated as "cs". Then named "DLScript", but that brought up some confusion, so we settled with
247
- GDNative. 📖
261
+ mistook a relation to C#, which is sometimes abbreviated as "cs". Then named
262
+ "DLScript", but that brought up some confusion, so we settled with GDNative. 📖
263
+
264
+ ## Updating Headers
265
+
266
+ See [ ** Versioning** ] ( #versioning ) for details on the Godot versions tracked by
267
+ each branch of this repository.
268
+
269
+ If the relevant branch is not up-to-date for your needs, or if you want to sync
270
+ the headers with your own modified version of Godot, here is the update
271
+ procedure used to sync this repository with upstream releases:
272
+
273
+ - Compile [ Godot Engine] ( https://github.com/godotengine/godot ) at the specific
274
+ version/commit which you are using.
275
+ - Use the compiled executable to generate the ` api.json ` file with:
276
+ ` godot --gdnative-generate-json-api api.json `
277
+ - Copy the file ` modules/gdnative/gdnative_api.json ` to this repository.
278
+ - Copy the files and folders from ` modules/gdnative/include ` to this repository,
279
+ overwriting existing content. (To be sure to be in sync, you can delete the
280
+ folders of this repository first, then copy the upstream folders in place.)
281
+ Make sure that you compiled the correct Godot version so that the generated
282
+ ` gdnative_api_struct.gen.h ` is up-to-date.
0 commit comments