1- # godot_headers  
2- #### ` GDNative / NativeScript `  
1+ # godot-headers  
32
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 ) .
59
610>  ` NativeScript `  uses GDNative to implement scripts backed by native code.
711
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  
1118
12- ## Branches  
19+ This repositories follows the same branch versioning as the main [ Godot Engine
20+ repository] ( https://github.com/godotengine/godot ) :
1321
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.
1630
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. ** 
2337
2438## Getting Started  
2539
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 )  | 
2741|  --- |  --- |  --- | 
2842
29- ### Clone godot_headers  into Library  
43+ ### Clone ` godot-headers `  into Library  
3044
31- Clone ` godot_headers `  under ` SimpleLibrary/ ` 
45+ Clone ` godot-headers `  under ` SimpleLibrary/ ` 
3246
3347``` bash 
3448cd  SimpleLibrary
35- git clone https://github.com/GodotNativeTools/godot_headers 
49+ git clone https://github.com/godotengine/godot-headers 
3650``` 
3751
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 ` ).
4156
4257``` bash 
4358[SimpleLibrary]
@@ -47,7 +62,7 @@ git clone https://github.com/GodotNativeTools/godot_headers
4762
4863### Create Script  
4964
50- Create ` test.c `  under ` SimpleLibrary/src/ ` 
65+ Create ` test.c `  under ` SimpleLibrary/src/ ` . 
5166
5267<details >
5368
@@ -58,22 +73,22 @@ Create `test.c` under `SimpleLibrary/src/`
5873#include  < stdio.h> 
5974
6075void  *test_constructor (godot_object * obj, void * method_data) {
61-          printf("test.constructor()\n");
62-          return 0;
76+ 	 printf("test.constructor()\n");
77+ 	 return 0;
6378}
6479
6580void test_destructor(godot_object * obj, void * method_data, void * user_data) {
66-          printf("test.destructor()\n");
81+ 	 printf("test.destructor()\n");
6782}
6883
6984/**  func _ ready() ** /
7085godot_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);
7388
74-           printf("_ready()\n");
89+ 	 printf("_ready()\n"); 
7590
76-           return ret;
91+ 	 return ret; 
7792}
7893
7994/**  Library entry point ** /
@@ -90,64 +105,64 @@ void GDN_EXPORT godot_nativescript_init(void *desc) {
90105
91106	godot_instance_create_func create_func = { 
92107		.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+ 	 } 
118133}
119134
120135godot_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);
123138
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); 
127142
128-           godot_string_destroy(&s);
143+ 	 godot_string_destroy(&s); 
129144
130-           return ret;
145+ 	 return ret; 
131146}
132147``` 
133148
134149</details> 
135150
136- ` Expand details  for example code.` 
151+ Expand *Details*  for example code. 
137152
138153### Compile Library 
139154
140155On Linux: 
141156
142157```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 
144159clang -g -shared src/test.os -o lib/test.so 
145160``` 
146161
147162On MacOS:
148163
149164``` 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
151166clang -g -shared -framework Cocoa -Wl,-undefined,dynamic_lookup src/test.os -o lib/test.dylib
152167``` 
153168
@@ -158,9 +173,9 @@ clang -g -shared -framework Cocoa -Wl,-undefined,dynamic_lookup src/test.os -o l
158173The GDNativeLibrary resource contains links to the libraries for each platform.
159174
1601751 .  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 ` 
164179
165180<details >
166181
@@ -174,33 +189,33 @@ The GDNativeLibrary resource contains links to the libraries for each platform.
174189
175190</details >
176191
177- ` Expand details  for screenshots. ` 
192+ Expand * Details *  for screenshots.
178193
179194### Using GDNativeLibrary in GDScript  
180195
181196``` gdscript 
182197extends Node 
183198
184199func _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")
187202
188-          gdn.initialize()
203+ 	 gdn.initialize()
189204
190-          var res = gdn.call_native("standard_varcall", "some_test_procedure", [])
205+ 	 var res = gdn.call_native("standard_varcall", "some_test_procedure", [])
191206
192-          print("result: ", res)
207+ 	 print("result: ", res)
193208
194-          gdn.terminate()
209+ 	 gdn.terminate()
195210``` 
196211
197212### Attaching GDNativeLibrary to a Node  
198213
1992141 .  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 ` .
204219
205220The GDNativeLibrary field in a NativeScript is empty by default.
206221
@@ -213,7 +228,7 @@ The GDNativeLibrary field in a NativeScript is empty by default.
213228
214229</details >
215230
216- ` Expand details  for screenshots. ` 
231+ Expand * Details *  for screenshots.
217232
218233## FAQ  
219234
@@ -227,8 +242,8 @@ use of GDNative to implement scripts backed by native code.
227242
228243** Which languages are binding as a NativeScript?** 
229244
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  ) ,
232247[ ** Nim** ] ( https://github.com/pragmagic/godot-nim ) 
233248
234249** Can you debug NativeScripts?** 
@@ -243,5 +258,25 @@ You can! ✨
243258** What is the reason behind the name "GDNative"?** 
244259
245260GDNative 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