Fix templates.

This commit is contained in:
Relintai 2023-06-02 17:59:23 +02:00
parent a2942c51e6
commit 34eca3bf35
15 changed files with 310 additions and 301 deletions

View File

@ -57,7 +57,7 @@ cdef class Array:
if not iterable:
gdapi10.pandemonium_array_new(&self._gd_data)
elif isinstance(iterable, Array):
self._gd_data = gdapi10.pandemonium_array_duplicate(&(<Array>iterable)._gd_data, False)
self._gd_data = gdapi10.pandemonium_array_duplicate(&(<Array>iterable)._gd_data)
# TODO: handle Pool*Array
else:
gdapi10.pandemonium_array_new(&self._gd_data)
@ -96,7 +96,9 @@ cdef class Array:
cdef inline Array operator_getslice(self, pandemonium_int start, pandemonium_int stop, pandemonium_int step):
{{ force_mark_rendered("pandemonium_array_slice") }}
cdef Array ret = Array.__new__(Array)
ret._gd_data = gdapi10.pandemonium_array_slice(&self._gd_data, start, stop, step, False)
#TODO
#ret._gd_data = gdapi10.pandemonium_array_slice_step(&self._gd_data, start, stop, step, False)
ret._gd_data = gdapi10.pandemonium_array_slice(&self._gd_data, start, stop)
return ret
# TODO: support slice

View File

@ -191,7 +191,7 @@ cdef class Basis:
return Basis_multiply_scalar(self, val)
else:
return Basis_multiply_vector(self, _val)
return Basis_multiply(self, _val)
{{ render_method("as_string") | indent }}
{{ render_method("inverse") | indent }}

View File

@ -9,52 +9,57 @@ from pandemonium.pool_arrays cimport (
PoolRealArray,
PoolByteArray,
PoolVector2Array,
PoolVector2iArray,
PoolVector3Array,
PoolVector3iArray,
PoolVector4Array,
PoolVector4iArray,
PoolColorArray,
PoolStringArray,
)
{% set render_target = "rid" %}
{% include 'render.tmpl.pyi' with context %}
{% include 'render.tmpl.pxd' with context %}
{% set render_target = "vector3" %}
{% include 'render.tmpl.pyi' with context %}
{% include 'render.tmpl.pxd' with context %}
{% set render_target = "vector2" %}
{% include 'render.tmpl.pyi' with context %}
{% include 'render.tmpl.pxd' with context %}
{% set render_target = "vector2i" %}
{% include 'render.tmpl.pyx' with context %}
{% include 'render.tmpl.pxd' with context %}
{% set render_target = "vector3i" %}
{% include 'render.tmpl.pyx' with context %}
{% include 'render.tmpl.pxd' with context %}
{% set render_target = "vector4" %}
{% include 'render.tmpl.pyx' with context %}
{% include 'render.tmpl.pxd' with context %}
{% set render_target = "vector4i" %}
{% include 'render.tmpl.pyx' with context %}
{% include 'render.tmpl.pxd' with context %}
{% set render_target = "aabb" %}
{% include 'render.tmpl.pyi' with context %}
{% include 'render.tmpl.pxd' with context %}
{% set render_target = "basis" %}
{% include 'render.tmpl.pyi' with context %}
{% include 'render.tmpl.pxd' with context %}
{% set render_target = "color" %}
{% include 'render.tmpl.pyi' with context %}
{% include 'render.tmpl.pxd' with context %}
{% set render_target = "gdstring" %}
{% include 'render.tmpl.pyi' with context %}
{% include 'render.tmpl.pxd' with context %}
{% set render_target = "rect2" %}
{% include 'render.tmpl.pyi' with context %}
{% include 'render.tmpl.pxd' with context %}
{% set render_target = "rect2i" %}
{% include 'render.tmpl.pyx' with context %}
{% include 'render.tmpl.pxd' with context %}
{% set render_target = "projection" %}
{% include 'render.tmpl.pyx' with context %}
{% include 'render.tmpl.pxd' with context %}
{% set render_target = "transform2d" %}
{% include 'render.tmpl.pyi' with context %}
{% include 'render.tmpl.pxd' with context %}
{% set render_target = "plane" %}
{% include 'render.tmpl.pyi' with context %}
{% include 'render.tmpl.pxd' with context %}
{% set render_target = "quaternion" %}
{% include 'render.tmpl.pyi' with context %}
{% include 'render.tmpl.pxd' with context %}
{% set render_target = "transform" %}
{% include 'render.tmpl.pyi' with context %}
{% include 'render.tmpl.pxd' with context %}
{% set render_target = "node_path" %}
{% include 'render.tmpl.pyi' with context %}
{% include 'render.tmpl.pxd' with context %}
{% set render_target = "string_name" %}
{% include 'render.tmpl.pyx' with context %}
{% include 'render.tmpl.pxd' with context %}
{% set render_target = "dictionary" %}
{% include 'render.tmpl.pyi' with context %}
{% include 'render.tmpl.pxd' with context %}
{% set render_target = "array" %}
{% include 'render.tmpl.pyi' with context %}
{% include 'render.tmpl.pxd' with context %}

View File

@ -10,13 +10,13 @@ from typing import Union
{% set render_target = "vector2" %}
{% include 'render.tmpl.pyi' with context %}
{% set render_target = "vector2i" %}
{% include 'render.tmpl.pyx' with context %}
{% include 'render.tmpl.pyi' with context %}
{% set render_target = "vector3i" %}
{% include 'render.tmpl.pyx' with context %}
{% include 'render.tmpl.pyi' with context %}
{% set render_target = "vector4" %}
{% include 'render.tmpl.pyx' with context %}
{% include 'render.tmpl.pyi' with context %}
{% set render_target = "vector4i" %}
{% include 'render.tmpl.pyx' with context %}
{% include 'render.tmpl.pyi' with context %}
{% set render_target = "aabb" %}
{% include 'render.tmpl.pyi' with context %}
{% set render_target = "basis" %}
@ -28,9 +28,9 @@ from typing import Union
{% set render_target = "rect2" %}
{% include 'render.tmpl.pyi' with context %}
{% set render_target = "rect2i" %}
{% include 'render.tmpl.pyx' with context %}
{% include 'render.tmpl.pyi' with context %}
{% set render_target = "projection" %}
{% include 'render.tmpl.pyx' with context %}
{% include 'render.tmpl.pyi' with context %}
{% set render_target = "transform2d" %}
{% include 'render.tmpl.pyi' with context %}
{% set render_target = "plane" %}
@ -42,7 +42,7 @@ from typing import Union
{% set render_target = "node_path" %}
{% include 'render.tmpl.pyi' with context %}
{% set render_target = "string_name" %}
{% include 'render.tmpl.pyx' with context %}
{% include 'render.tmpl.pyi' with context %}
{% set render_target = "dictionary" %}
{% include 'render.tmpl.pyi' with context %}
{% set render_target = "array" %}

View File

@ -89,7 +89,7 @@ cdef class Projection:
&(<Vector4?>x_axis)._gd_data,
&(<Vector4?>y_axis)._gd_data,
&(<Vector4?>z_axis)._gd_data,
&(<Vector4?>origin)._gd_data,
&(<Vector4?>w_axis)._gd_data,
)
def __repr__(Projection self):

View File

@ -31,7 +31,7 @@
@cython.final
cdef class Quaternion:
{% block cdef_attributes %}
cdef pandemonium_quat _gd_data
cdef pandemonium_quaternion _gd_data
{% endblock %}
{% block python_defs %}

View File

@ -43,7 +43,7 @@ cdef class Rect2i:
gdapi10.pandemonium_rect2i_new(&self._gd_data, x, y, width, height)
@staticmethod
def from_pos_size(Vector2 position not None, Vector2 size not None):
def from_pos_size(Vector2i position not None, Vector2i size not None):
{{ force_mark_rendered("pandemonium_rect2i_new_with_position_and_size") }}
cdef Rect2i ret = Rect2i.__new__(Rect2i)
gdapi10.pandemonium_rect2i_new_with_position_and_size(&ret._gd_data, &position._gd_data, &size._gd_data)
@ -59,10 +59,10 @@ cdef class Rect2i:
{{ render_property("position", getter="get_position", setter="set_position") | indent }}
@property
def end(Rect2i self) -> Vector2:
def end(Rect2i self) -> Vector2i:
cdef pandemonium_vector2i position = gdapi10.pandemonium_rect2i_get_position(&self._gd_data)
cdef pandemonium_vector2i size = gdapi10.pandemonium_rect2i_get_size(&self._gd_data)
cdef Vector2 ret = Vector2.__new__(Vector2)
cdef Vector2i ret = Vector2i.__new__(Vector2i)
ret._gd_data = gdapi10.pandemonium_vector2i_operator_add(&position, &size)
return ret

View File

@ -14,12 +14,12 @@ cdef class StringName:
{{ force_mark_rendered("pandemonium_string_name_new") }}
cdef pandemonium_string gd_from
try:
gdapi10.pandemonium_string_name_new(&self._gd_data, &(<GDString?>from_)._gd_data)
gdapi10.pandemonium_string_name_new_data_string(&self._gd_data, &(<GDString?>from_)._gd_data)
except TypeError:
if not isinstance(from_, str):
raise TypeError("`from_` must be str or GDString")
pyobj_to_pandemonium_string(from_, &gd_from)
gdapi10.pandemonium_string_name_new(&self._gd_data, &gd_from)
gdapi10.pandemonium_string_name_new_data_string(&self._gd_data, &gd_from)
gdapi10.pandemonium_string_destroy(&gd_from)
def __dealloc__(StringName self):
@ -34,8 +34,8 @@ cdef class StringName:
def __str__(StringName self):
return str(self.get_name())
{{ render_operator_eq() | indent }}
{{ render_operator_ne() | indent }}
#{{ render_operator_eq() | indent }}
#{{ render_operator_ne() | indent }}
{{ render_method("destroy") | indent }}
{{ render_method("get_name") | indent }}

View File

@ -58,27 +58,27 @@ cdef class Vector2i:
{{ render_method("operator_add", py_name="__add__") | indent }}
{{ render_method("operator_subtract", py_name="__sub__") | indent }}
def __mul__(Vector2i self, val):
cdef Vector2i _val
try:
_val = <Vector2i?>val
except TypeError:
return Vector2i_multiply_scalar(self, val)
else:
return Vector2i_multiply_vector(self, _val)
#def __mul__(Vector2i self, val):
# cdef Vector2i _val
# try:
# _val = <Vector2i?>val
# except TypeError:
# return Vector2i_multiply_scalar(self, val)
# else:
# return Vector2i_multiply_vector(self, _val)
def __truediv__(Vector2i self, val):
cdef Vector2i _val
try:
_val = <Vector2i?>val
except TypeError:
if val is 0:
raise ZeroDivisionError()
return Vector2i_divide_scalar(self, val)
else:
if _val.x == 0 or _val.y == 0:
raise ZeroDivisionError()
return Vector2i_divide_vector(self, _val)
#def __truediv__(Vector2i self, val):
# cdef Vector2i _val
# try:
# _val = <Vector2i?>val
# except TypeError:
# if val is 0:
# raise ZeroDivisionError()
# return Vector2i_divide_scalar(self, val)
# else:
# if _val.x == 0 or _val.y == 0:
# raise ZeroDivisionError()
# return Vector2i_divide_vector(self, _val)
{{ render_property("x", "get_x", "set_x") | indent }}
{{ render_property("y", "get_y", "set_y") | indent }}

View File

@ -90,27 +90,27 @@ cdef class Vector3i:
{{ render_method("operator_add", py_name="__add__") | indent }}
{{ render_method("operator_subtract", py_name="__sub__") | indent }}
def __mul__(Vector3i self, val):
cdef Vector3i _val
try:
_val = <Vector3i?>val
except TypeError:
return Vector3i_multiply_scalar(self, val)
else:
return Vector3i_multiply_vector(self, _val)
#def __mul__(Vector3i self, val):
# cdef Vector3i _val
# try:
# _val = <Vector3i?>val
# except TypeError:
# return Vector3i_multiply_scalar(self, val)
# else:
# return Vector3i_multiply_vector(self, _val)
def __truediv__(Vector3i self, val):
cdef Vector3i _val
try:
_val = <Vector3i?>val
except TypeError:
if val is 0:
raise ZeroDivisionError()
return Vector3i_divide_scalar(self, val)
else:
if _val.x == 0 or _val.y == 0 or _val.z == 0:
raise ZeroDivisionError()
return Vector3i_divide_vector(self, _val)
#def __truediv__(Vector3i self, val):
# cdef Vector3i _val
# try:
# _val = <Vector3i?>val
# except TypeError:
# if val is 0:
# raise ZeroDivisionError()
# return Vector3i_divide_scalar(self, val)
# else:
# if _val.x == 0 or _val.y == 0 or _val.z == 0:
# raise ZeroDivisionError()
# return Vector3i_divide_vector(self, _val)
{{ render_method("as_string") | indent }}
{% endblock %}

View File

@ -92,27 +92,27 @@ cdef class Vector4i:
{{ render_method("operator_add", py_name="__add__") | indent }}
{{ render_method("operator_subtract", py_name="__sub__") | indent }}
def __mul__(Vector4i self, val):
cdef Vector4i _val
try:
_val = <Vector4i?>val
except TypeError:
return Vector4i_multiply_scalar(self, val)
else:
return Vector4i_multiply_vector(self, _val)
#def __mul__(Vector4i self, val):
# cdef Vector4i _val
# try:
# _val = <Vector4i?>val
# except TypeError:
# return Vector4i_multiply_scalar(self, val)
# else:
# return Vector4i_multiply_vector(self, _val)
def __truediv__(Vector4i self, val):
cdef Vector4i _val
try:
_val = <Vector4i?>val
except TypeError:
if val is 0:
raise ZeroDivisionError()
return Vector4i_divide_scalar(self, val)
else:
if _val.x == 0 or _val.y == 0 or _val.z == 0:
raise ZeroDivisionError()
return Vector4i_divide_vector(self, _val)
#def __truediv__(Vector4i self, val):
# cdef Vector4i _val
# try:
# _val = <Vector4i?>val
# except TypeError:
# if val is 0:
# raise ZeroDivisionError()
# return Vector4i_divide_scalar(self, val)
# else:
# if _val.x == 0 or _val.y == 0 or _val.z == 0:
# raise ZeroDivisionError()
# return Vector4i_divide_vector(self, _val)
{{ render_method("as_string") | indent }}
{% endblock %}

View File

@ -48,9 +48,9 @@ from pandemonium.tags import ExportedField, SignalField
cdef inline pandemonium_pluginscript_script_manifest _build_empty_script_manifest():
cdef pandemonium_pluginscript_script_manifest manifest
manifest.data = NULL
gdapi10.pandemonium_string_name_new_data(&manifest.name, "")
gdapi10.pandemonium_string_name_new_data_char(&manifest.name, "")
manifest.is_tool = False
gdapi10.pandemonium_string_name_new_data(&manifest.base, "")
gdapi10.pandemonium_string_name_new_data_char(&manifest.base, "")
gdapi10.pandemonium_dictionary_new(&manifest.member_lines)
gdapi10.pandemonium_array_new(&manifest.methods)
gdapi10.pandemonium_array_new(&manifest.signals)

View File

@ -1,5 +1,9 @@
from libc.stddef cimport wchar_t
from libc.stdio cimport printf
from libc.stdint cimport uint_least16_t, uint_least32_t
ctypedef uint_least16_t char16_t
ctypedef uint_least32_t char32_t
from pandemonium._hazmat.gdapi cimport pythonscript_gdapi10 as gdapi10
from pandemonium._hazmat.gdnative_api_struct cimport (
@ -31,11 +35,11 @@ DEF _STRING_CODEPOINT_LENGTH = 4
cdef inline str pandemonium_string_to_pyobj(const pandemonium_string *p_gdstr):
# TODO: unicode&windows support is most likely broken...
cdef char *raw = <char*>gdapi10.pandemonium_string_wide_str(p_gdstr)
cdef char *raw = <char*>gdapi10.pandemonium_string_get_data(p_gdstr)
cdef pandemonium_int length = gdapi10.pandemonium_string_length(p_gdstr)
return raw[:length * _STRING_CODEPOINT_LENGTH].decode(_STRING_ENCODING)
# cdef char *raw = <char*>gdapi10.pandemonium_string_wide_str(p_gdstr)
# cdef char *raw = <char*>gdapi10.pandemonium_string_get_data(p_gdstr)
# cdef pandemonium_int length = gdapi10.pandemonium_string_length(p_gdstr)
# printf("==========> pandemonium_string_to_pyobj ")
# cdef int i
@ -50,8 +54,8 @@ cdef inline str pandemonium_string_to_pyobj(const pandemonium_string *p_gdstr):
cdef inline void pyobj_to_pandemonium_string(str pystr, pandemonium_string *p_gdstr):
# TODO: unicode&windows support is most likely broken...
cdef bytes raw = pystr.encode(_STRING_ENCODING)
gdapi10.pandemonium_string_new_with_wide_string(
p_gdstr, (<wchar_t*><char*>raw), len(pystr)
gdapi10.pandemonium_string_newc_clip_to_len(
p_gdstr, (<char32_t*><char*>raw), len(pystr)
)
@ -61,11 +65,10 @@ cdef inline str pandemonium_string_name_to_pyobj(const pandemonium_string_name *
gdapi10.pandemonium_string_destroy(&strname)
return ret
cdef inline void pyobj_to_pandemonium_string_name(str pystr, pandemonium_string_name *p_gdname):
cdef pandemonium_string strname
pyobj_to_pandemonium_string(pystr, &strname)
gdapi10.pandemonium_string_name_new(p_gdname, &strname)
gdapi10.pandemonium_string_name_new_data_string(p_gdname, &strname)
gdapi10.pandemonium_string_destroy(&strname)

View File

@ -243,7 +243,7 @@ cdef inline Plane _pandemonium_variant_to_pyobj_plane(const pandemonium_variant
cdef inline Quaternion _pandemonium_variant_to_pyobj_quat(const pandemonium_variant *p_gdvar):
cdef Quaternion ret = Quaternion.__new__(Quaternion)
ret._gd_data = gdapi10.pandemonium_variant_as_quat(p_gdvar)
ret._gd_data = gdapi10.pandemonium_variant_as_quaternion(p_gdvar)
return ret
@ -358,7 +358,7 @@ cdef bint pyobj_to_pandemonium_variant(object pyobj, pandemonium_variant *p_var)
elif isinstance(pyobj, Plane):
gdapi10.pandemonium_variant_new_plane(p_var, &(<Plane>pyobj)._gd_data)
elif isinstance(pyobj, Quaternion):
gdapi10.pandemonium_variant_new_quat(p_var, &(<Quaternion>pyobj)._gd_data)
gdapi10.pandemonium_variant_new_quaternion(p_var, &(<Quaternion>pyobj)._gd_data)
elif isinstance(pyobj, AABB):
gdapi10.pandemonium_variant_new_aabb(p_var, &(<AABB>pyobj)._gd_data)
elif isinstance(pyobj, Basis):

View File

@ -20,7 +20,6 @@
#include "_pandemonium_api.h"
static const char *PYTHONSCRIPT_RECOGNIZED_EXTENSIONS[] = { "py", "pyc", "pyo", "pyd", 0 };
static const char *PYTHONSCRIPT_RESERVED_WORDS[] = {
"False",
@ -63,7 +62,6 @@ static const char *PYTHONSCRIPT_STRING_DELIMITERS[] = { "\" \"", "' '", 0 };
static pandemonium_pluginscript_language_desc desc;
static PyThreadState *gilstate = NULL;
/*
* Global variables exposing Pandemonium API to the pandemonium.hazmat cython module.
* Hence we must initialized them before loading `_pandemonium`/`pandemonium` modules
@ -79,7 +77,6 @@ PYTHONSCRIPT_EXPORT const pandemonium_gdnative_ext_nativescript_api_struct *pyth
PYTHONSCRIPT_EXPORT const pandemonium_gdnative_ext_pluginscript_api_struct *pythonscript_gdapi_ext_pluginscript = NULL;
PYTHONSCRIPT_EXPORT const pandemonium_gdnative_ext_android_api_struct *pythonscript_gdapi_ext_android = NULL;
static void _register_gdapi(const pandemonium_gdnative_init_options *options) {
pythonscript_gdapi10 = (const pandemonium_gdnative_core_api_struct *)options->api_struct;
/*
@ -109,14 +106,14 @@ static void _register_gdapi(const pandemonium_gdnative_init_options *options) {
}
}
GDN_EXPORT void pandemonium_gdnative_init(pandemonium_gdnative_init_options *options) {
// Registering the api should be the very first thing to do !
_register_gdapi(options);
// Now those macros are usable
#define GD_PRINT(c_msg) { \
#define GD_PRINT(c_msg) \
{ \
pandemonium_string gd_msg; \
pythonscript_gdapi10->pandemonium_string_new_with_wide_string( \
&gd_msg, c_msg, -1); \
@ -124,7 +121,8 @@ GDN_EXPORT void pandemonium_gdnative_init(pandemonium_gdnative_init_options *opt
pythonscript_gdapi10->pandemonium_string_destroy(&gd_msg); \
}
#define GD_ERROR_PRINT(msg) { \
#define GD_ERROR_PRINT(msg) \
{ \
pythonscript_gdapi10->pandemonium_print_error(msg, __func__, __FILE__, __LINE__); \
}
@ -144,9 +142,12 @@ GDN_EXPORT void pandemonium_gdnative_init(pandemonium_gdnative_init_options *opt
// Make sure the shared library has all it symbols loaded
// (strange bug with libpython3.x.so otherwise...)
{
const wchar_t *wpath = pythonscript_gdapi10->pandemonium_string_wide_str(
options->active_library_path
);
pandemonium_char_16_string wpstr = pythonscript_gdapi10->pandemonium_string_utf16(options->active_library_path);
const wchar_t *wpath = (wchar_t *)pythonscript_gdapi10->pandemonium_char_16_string_get_data(&wpstr);
//const wchar_t *wpath = pythonscript_gdapi10->pandemonium_string_wide_str(
// options->active_library_path
//);
char path[300];
wcstombs(path, wpath, 300);
dlopen(path, RTLD_NOW | RTLD_GLOBAL);
@ -165,9 +166,10 @@ GDN_EXPORT void pandemonium_gdnative_init(pandemonium_gdnative_init_options *opt
{
static wchar_t pythonhome[300];
pandemonium_string _pythonhome = pythonscript_gdapi10->pandemonium_string_get_base_dir(
options->active_library_path
);
wcsncpy(pythonhome, pythonscript_gdapi10->pandemonium_string_wide_str(&_pythonhome), 300);
options->active_library_path);
pandemonium_char_16_string wpstr = pythonscript_gdapi10->pandemonium_string_utf16(&_pythonhome);
wcsncpy(pythonhome, (wchar_t *)pythonscript_gdapi10->pandemonium_char_16_string_get_data(&wpstr), 300);
pythonscript_gdapi10->pandemonium_string_destroy(&_pythonhome);
Py_SetPythonHome(pythonhome);
}
@ -219,7 +221,6 @@ GDN_EXPORT void pandemonium_gdnative_init(pandemonium_gdnative_init_options *opt
desc.script_desc.instance_desc.refcount_decremented = NULL;
if (options->in_editor) {
desc.get_template_source_code = pythonscript_get_template_source_code;
desc.validate = pythonscript_validate;
desc.find_function = pythonscript_find_function;
@ -249,11 +250,9 @@ GDN_EXPORT void pandemonium_gdnative_init(pandemonium_gdnative_init_options *opt
gilstate = PyEval_SaveThread();
}
GDN_EXPORT void pandemonium_gdnative_singleton() {
}
GDN_EXPORT void pandemonium_gdnative_terminate() {
// Re-acquire the gil in order to finalize properly
PyEval_RestoreThread(gilstate);