mirror of
https://github.com/godotengine/godot-docs.git
synced 2026-01-03 05:48:42 +03:00
Style: Integrate new #pragma once syntax
This commit is contained in:
@@ -133,8 +133,7 @@ Create the file ``init.h`` in the ``src`` folder, with the following contents:
|
||||
|
||||
.. code-block:: c
|
||||
|
||||
#ifndef INIT_H
|
||||
#define INIT_H
|
||||
#pragma once
|
||||
|
||||
#include "defs.h"
|
||||
|
||||
@@ -144,8 +143,6 @@ Create the file ``init.h`` in the ``src`` folder, with the following contents:
|
||||
void deinitialize_gdexample_module(void *p_userdata, GDExtensionInitializationLevel p_level);
|
||||
GDExtensionBool GDE_EXPORT gdexample_library_init(GDExtensionInterfaceGetProcAddress p_get_proc_address, GDExtensionClassLibraryPtr p_library, GDExtensionInitialization *r_initialization);
|
||||
|
||||
#endif // INIT_H
|
||||
|
||||
The functions declared here have the signatures expected by the GDExtension API.
|
||||
|
||||
Note the inclusion of the ``defs.h`` file. This is one of our helpers to
|
||||
@@ -158,8 +155,7 @@ Create the ``defs.h`` file in the ``src`` folder with the following contents:
|
||||
|
||||
.. code-block:: c
|
||||
|
||||
#ifndef DEFS_H
|
||||
#define DEFS_H
|
||||
#pragma once
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
@@ -175,8 +171,6 @@ Create the ``defs.h`` file in the ``src`` folder with the following contents:
|
||||
#endif
|
||||
#endif // ! GDE_EXPORT
|
||||
|
||||
#endif // DEFS_H
|
||||
|
||||
We also include some standard headers to make things easier. Now we only have to
|
||||
include ``defs.h`` and those will come as a bonus.
|
||||
|
||||
@@ -224,8 +218,7 @@ contents:
|
||||
|
||||
.. code-block:: c
|
||||
|
||||
#ifndef GDEXAMPLE_H
|
||||
#define GDEXAMPLE_H
|
||||
#pragma once
|
||||
|
||||
#include "gdextension_interface.h"
|
||||
|
||||
@@ -247,8 +240,6 @@ contents:
|
||||
// Bindings.
|
||||
void gdexample_class_bind_methods();
|
||||
|
||||
#endif // GDEXAMPLE_H
|
||||
|
||||
Noteworthy here is the ``object`` field, which holds a pointer to
|
||||
the Godot object, and the ``gdexample_class_bind_methods()`` function, which will
|
||||
register the metadata of our custom class (properties, methods, and signals).
|
||||
@@ -299,8 +290,7 @@ We'll start by creating an ``api.h`` file in the ``src`` folder:
|
||||
|
||||
.. code-block:: c
|
||||
|
||||
#ifndef API_H
|
||||
#define API_H
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
This file works as a collection of helpers to call the GDExtension API
|
||||
@@ -333,10 +323,6 @@ We'll start by creating an ``api.h`` file in the ``src`` folder:
|
||||
|
||||
void load_api(GDExtensionInterfaceGetProcAddress p_get_proc_address);
|
||||
|
||||
|
||||
|
||||
#endif // API_H
|
||||
|
||||
This file will include many other helpers as we fill our extension with
|
||||
something useful. For now it only has a pointer to a function that creates a
|
||||
StringName from a C string (in Latin-1 encoding) and another to destruct a
|
||||
|
||||
@@ -164,8 +164,7 @@ GDExtension node we'll be creating. We will name it ``gdexample.h``:
|
||||
.. code-block:: cpp
|
||||
:caption: gdextension_cpp_example/src/gdexample.h
|
||||
|
||||
#ifndef GDEXAMPLE_H
|
||||
#define GDEXAMPLE_H
|
||||
#pragma once
|
||||
|
||||
#include <godot_cpp/classes/sprite2d.hpp>
|
||||
|
||||
@@ -187,9 +186,7 @@ GDExtension node we'll be creating. We will name it ``gdexample.h``:
|
||||
void _process(double delta) override;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
} // namespace godot
|
||||
|
||||
There are a few things of note to the above. We include ``sprite2d.hpp`` which
|
||||
contains bindings to the Sprite2D class. We'll be extending this class in our
|
||||
@@ -313,8 +310,7 @@ At last, we need the header file for the ``register_types.cpp`` named
|
||||
.. code-block:: cpp
|
||||
:caption: gdextension_cpp_example/src/register_types.h
|
||||
|
||||
#ifndef GDEXAMPLE_REGISTER_TYPES_H
|
||||
#define GDEXAMPLE_REGISTER_TYPES_H
|
||||
#pragma once
|
||||
|
||||
#include <godot_cpp/core/class_db.hpp>
|
||||
|
||||
@@ -323,9 +319,6 @@ At last, we need the header file for the ``register_types.cpp`` named
|
||||
void initialize_example_module(ModuleInitializationLevel p_level);
|
||||
void uninitialize_example_module(ModuleInitializationLevel p_level);
|
||||
|
||||
#endif // GDEXAMPLE_REGISTER_TYPES_H
|
||||
|
||||
|
||||
Compiling the plugin
|
||||
--------------------
|
||||
|
||||
|
||||
Reference in New Issue
Block a user