Skip to content

Commit

Permalink
Add basic spx extention api
Browse files Browse the repository at this point in the history
  • Loading branch information
JiepengTan committed Aug 16, 2024
1 parent 9b4cebc commit 6cd9ba4
Show file tree
Hide file tree
Showing 29 changed files with 2,512 additions and 72 deletions.
184 changes: 184 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
default_language_version:
python: python3

exclude: |
(?x)^(
.*thirdparty/.*|
.*-so_wrap\.(h|c)$
)
repos:
- repo: https://github.com/pre-commit/mirrors-clang-format
rev: v17.0.6
hooks:
- id: clang-format
files: \.(c|h|cpp|hpp|cc|hh|cxx|hxx|m|mm|inc|java|glsl)$
types_or: [text]
exclude: |
(?x)^(
tests/python_build/.*|
platform/android/java/lib/src/com/.*
)
- repo: https://github.com/pocc/pre-commit-hooks
rev: v1.3.5
hooks:
- id: clang-tidy
files: \.(c|h|cpp|hpp|cc|hh|cxx|hxx|m|mm|inc|java|glsl)$
args: [--fix, --quiet, --use-color]
types_or: [text]
exclude: |
(?x)^(
tests/python_build/.*|
platform/android/java/lib/src/com/.*
)
additional_dependencies: [clang-tidy==18.1.1]
require_serial: true
stages: [manual] # Not automatically triggered, invoked via `pre-commit run --hook-stage manual clang-tidy`

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.4.4
hooks:
- id: ruff
args: [--fix]
- id: ruff-format

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.971
hooks:
- id: mypy
files: \.py$
types_or: [text]

- repo: https://github.com/codespell-project/codespell
rev: v2.3.0
hooks:
- id: codespell
additional_dependencies: [tomli]

### Requires Docker; look into alternative implementation.
# - repo: https://github.com/comkieffer/pre-commit-xmllint.git
# rev: 1.0.0
# hooks:
# - id: xmllint
# language: docker
# types_or: [text]
# files: ^(doc/classes|.*/doc_classes)/.*\.xml$
# args: [--schema, doc/class.xsd]

- repo: local
hooks:
- id: make-rst
name: make-rst
language: python
entry: python doc/tools/make_rst.py
args: [doc/classes, modules, platform, --dry-run, --color]
pass_filenames: false
files: ^(doc/classes|.*/doc_classes)/.*\.xml$

- id: doc-status
name: doc-status
language: python
entry: python doc/tools/doc_status.py
args: [doc/classes, modules/*/doc_classes, platform/*/doc_classes]
pass_filenames: false
files: ^(doc/classes|.*/doc_classes)/.*\.xml$

- id: eslint
name: eslint
language: node
entry: eslint
files: ^(platform/web/js/|modules/|misc/dist/html/).*\.(js|html)$
args: [--fix, --no-warn-ignored, --no-config-lookup, --config, platform/web/eslint.config.cjs]
additional_dependencies:
- '@eslint/js@^9.3.0'
- '@html-eslint/eslint-plugin@^0.24.1'
- '@html-eslint/parser@^0.24.1'
- '@stylistic/eslint-plugin@^2.1.0'
- 'eslint@^9.3.0'
- 'eslint-plugin-html@^8.1.1'
- 'globals@^15.3.0'
- 'espree@^10.0.1'

- id: jsdoc
name: jsdoc
language: node
entry: jsdoc
files: ^platform/web/js/engine/(engine|config|features)\.js$
args:
- --template
- platform/web/js/jsdoc2rst/
- platform/web/js/engine/engine.js
- platform/web/js/engine/config.js
- platform/web/js/engine/features.js
- --destination
- ''
- -d
- dry-run
pass_filenames: false
additional_dependencies: ['jsdoc@^4.0.3']

- id: svgo
name: svgo
language: node
entry: svgo
files: \.svg$
args: [--quiet, --config, misc/utility/svgo.config.mjs]
additional_dependencies: ["[email protected]"]

- id: copyright-headers
name: copyright-headers
language: python
entry: python misc/scripts/copyright_headers.py
files: \.(c|h|cpp|hpp|cc|hh|cxx|hxx|m|mm|inc|java)$
exclude: |
(?x)^(
core/math/bvh_.*\.inc$|
platform/(?!android|ios|linuxbsd|macos|web|windows)\w+/.*|
platform/android/java/lib/src/com/.*|
platform/android/java/lib/src/org/godotengine/godot/gl/GLSurfaceView\.java$|
platform/android/java/lib/src/org/godotengine/godot/gl/EGLLogWrapper\.java$|
platform/android/java/lib/src/org/godotengine/godot/utils/ProcessPhoenix\.java$
)
- id: header-guards
name: header-guards
language: python
entry: python misc/scripts/header_guards.py
files: \.(h|hpp|hh|hxx)$
exclude: ^.*/(thread|platform_config|platform_gl)\.h$

- id: file-format
name: file-format
language: python
entry: python misc/scripts/file_format.py
types_or: [text]
exclude: |
(?x)^(
.*\.test\.txt$|
.*\.svg$|
.*\.patch$|
.*\.out$|
modules/gdscript/tests/scripts/parser/features/mixed_indentation_on_blank_lines\.gd$|
modules/gdscript/tests/scripts/parser/warnings/empty_file_newline_comment\.notest\.gd$|
modules/gdscript/tests/scripts/parser/warnings/empty_file_newline\.notest\.gd$|
platform/android/java/lib/src/com/google/.*
)
- id: dotnet-format
name: dotnet-format
language: python
entry: python misc/scripts/dotnet_format.py
types_or: [c#]

# End of upstream Godot pre-commit hooks.
#
# Keep this separation to let downstream forks add their own hooks to this file,
# without running into merge conflicts when rebasing on latest upstream.
#
# Start of downstream pre-commit hooks.
#
# This is still the "repo: local" scope, so new local hooks can be defined directly at this indentation:
# - id: new-local-hook
# To add external repo hooks, bring the indentation back to:
# - repo: my-remote-hook
39 changes: 37 additions & 2 deletions core/extension/gdextension_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include "core/config/engine.h"
#include "core/extension/gdextension.h"
#include "core/extension/gdextension_compat_hashes.h"
#include "core/extension/gdextension_spx_ext.h"
#include "core/io/file_access.h"
#include "core/io/xml_parser.h"
#include "core/object/class_db.h"
Expand All @@ -41,7 +42,6 @@
#include "core/os/memory.h"
#include "core/variant/variant.h"
#include "core/version.h"
#include "core/extension/extension_spx_ext.cpp"

class CallableCustomExtension : public CallableCustom {
void *userdata;
Expand Down Expand Up @@ -1376,7 +1376,43 @@ static void gdextension_editor_remove_plugin(GDExtensionConstStringNamePtr p_cla

#define REGISTER_INTERFACE_FUNC(m_name) GDExtension::register_interface_function(#m_name, (GDExtensionInterfaceFunctionPtr)&gdextension_##m_name)

static void gdextension_spx_string_new_with_latin1_chars(GDExtensionUninitializedStringPtr r_dest, const char *p_contents) {
gdextension_string_new_with_latin1_chars(r_dest, p_contents);
}
static void gdextension_spx_string_new_with_utf8_chars(GDExtensionUninitializedStringPtr r_dest, const char *p_contents) {
gdextension_string_new_with_utf8_chars(r_dest, p_contents);
}
static void gdextension_spx_string_new_with_latin1_chars_and_len(GDExtensionUninitializedStringPtr r_dest, const char *p_contents, GDExtensionInt p_size) {
gdextension_string_new_with_latin1_chars_and_len(r_dest, p_contents, p_size);
}
static void gdextension_spx_string_new_with_utf8_chars_and_len(GDExtensionUninitializedStringPtr r_dest, const char *p_contents, GDExtensionInt p_size) {
gdextension_string_new_with_utf8_chars_and_len(r_dest, p_contents, p_size);
}
static GDExtensionInt gdextension_spx_string_to_latin1_chars(GDExtensionConstStringPtr p_self, char *r_text, GDExtensionInt p_max_write_length) {
return gdextension_string_to_latin1_chars(p_self, r_text, p_max_write_length);
}
static GDExtensionInt gdextension_spx_string_to_utf8_chars(GDExtensionConstStringPtr p_self, char *r_text, GDExtensionInt p_max_write_length) {
return gdextension_string_to_utf8_chars(p_self, r_text, p_max_write_length);
}
static GDExtensionPtrConstructor gdextension_spx_variant_get_ptr_constructor(GDExtensionVariantType p_type, int32_t p_constructor) {
return gdextension_variant_get_ptr_constructor(p_type, p_constructor);
}
static GDExtensionPtrDestructor gdextension_spx_variant_get_ptr_destructor(GDExtensionVariantType p_type) {
return gdextension_variant_get_ptr_destructor(p_type);
}
void setup_spx_interface() {
REGISTER_INTERFACE_FUNC(spx_string_new_with_latin1_chars);
REGISTER_INTERFACE_FUNC(spx_string_new_with_utf8_chars);
REGISTER_INTERFACE_FUNC(spx_string_new_with_latin1_chars_and_len);
REGISTER_INTERFACE_FUNC(spx_string_new_with_utf8_chars_and_len);
REGISTER_INTERFACE_FUNC(spx_string_to_latin1_chars);
REGISTER_INTERFACE_FUNC(spx_string_to_utf8_chars);
REGISTER_INTERFACE_FUNC(spx_variant_get_ptr_constructor);
REGISTER_INTERFACE_FUNC(spx_variant_get_ptr_destructor);
gdextension_spx_setup_interface();
}
void gdextension_setup_interface() {
setup_spx_interface();
REGISTER_INTERFACE_FUNC(get_godot_version);
REGISTER_INTERFACE_FUNC(mem_alloc);
REGISTER_INTERFACE_FUNC(mem_realloc);
Expand Down Expand Up @@ -1517,7 +1553,6 @@ void gdextension_setup_interface() {
REGISTER_INTERFACE_FUNC(classdb_get_class_tag);
REGISTER_INTERFACE_FUNC(editor_add_plugin);
REGISTER_INTERFACE_FUNC(editor_remove_plugin);
gdextension_spx_ext();
}

#undef REGISTER_INTERFACE_FUNCTION
Loading

0 comments on commit 6cd9ba4

Please sign in to comment.