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: if not iterable:
gdapi10.pandemonium_array_new(&self._gd_data) gdapi10.pandemonium_array_new(&self._gd_data)
elif isinstance(iterable, Array): 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 # TODO: handle Pool*Array
else: else:
gdapi10.pandemonium_array_new(&self._gd_data) 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): cdef inline Array operator_getslice(self, pandemonium_int start, pandemonium_int stop, pandemonium_int step):
{{ force_mark_rendered("pandemonium_array_slice") }} {{ force_mark_rendered("pandemonium_array_slice") }}
cdef Array ret = Array.__new__(Array) 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 return ret
# TODO: support slice # TODO: support slice

View File

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

View File

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

View File

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

View File

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

View File

@ -43,7 +43,7 @@ cdef class Rect2i:
gdapi10.pandemonium_rect2i_new(&self._gd_data, x, y, width, height) gdapi10.pandemonium_rect2i_new(&self._gd_data, x, y, width, height)
@staticmethod @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") }} {{ force_mark_rendered("pandemonium_rect2i_new_with_position_and_size") }}
cdef Rect2i ret = Rect2i.__new__(Rect2i) cdef Rect2i ret = Rect2i.__new__(Rect2i)
gdapi10.pandemonium_rect2i_new_with_position_and_size(&ret._gd_data, &position._gd_data, &size._gd_data) 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 }} {{ render_property("position", getter="get_position", setter="set_position") | indent }}
@property @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 position = gdapi10.pandemonium_rect2i_get_position(&self._gd_data)
cdef pandemonium_vector2i size = gdapi10.pandemonium_rect2i_get_size(&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) ret._gd_data = gdapi10.pandemonium_vector2i_operator_add(&position, &size)
return ret return ret

View File

@ -14,12 +14,12 @@ cdef class StringName:
{{ force_mark_rendered("pandemonium_string_name_new") }} {{ force_mark_rendered("pandemonium_string_name_new") }}
cdef pandemonium_string gd_from cdef pandemonium_string gd_from
try: 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: except TypeError:
if not isinstance(from_, str): if not isinstance(from_, str):
raise TypeError("`from_` must be str or GDString") raise TypeError("`from_` must be str or GDString")
pyobj_to_pandemonium_string(from_, &gd_from) 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) gdapi10.pandemonium_string_destroy(&gd_from)
def __dealloc__(StringName self): def __dealloc__(StringName self):
@ -34,8 +34,8 @@ cdef class StringName:
def __str__(StringName self): def __str__(StringName self):
return str(self.get_name()) return str(self.get_name())
{{ render_operator_eq() | indent }} #{{ render_operator_eq() | indent }}
{{ render_operator_ne() | indent }} #{{ render_operator_ne() | indent }}
{{ render_method("destroy") | indent }} {{ render_method("destroy") | indent }}
{{ render_method("get_name") | 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_add", py_name="__add__") | indent }}
{{ render_method("operator_subtract", py_name="__sub__") | indent }} {{ render_method("operator_subtract", py_name="__sub__") | indent }}
def __mul__(Vector2i self, val): #def __mul__(Vector2i self, val):
cdef Vector2i _val # cdef Vector2i _val
try: # try:
_val = <Vector2i?>val # _val = <Vector2i?>val
except TypeError: # except TypeError:
return Vector2i_multiply_scalar(self, val) # return Vector2i_multiply_scalar(self, val)
else: # else:
return Vector2i_multiply_vector(self, _val) # return Vector2i_multiply_vector(self, _val)
def __truediv__(Vector2i self, val): #def __truediv__(Vector2i self, val):
cdef Vector2i _val # cdef Vector2i _val
try: # try:
_val = <Vector2i?>val # _val = <Vector2i?>val
except TypeError: # except TypeError:
if val is 0: # if val is 0:
raise ZeroDivisionError() # raise ZeroDivisionError()
return Vector2i_divide_scalar(self, val) # return Vector2i_divide_scalar(self, val)
else: # else:
if _val.x == 0 or _val.y == 0: # if _val.x == 0 or _val.y == 0:
raise ZeroDivisionError() # raise ZeroDivisionError()
return Vector2i_divide_vector(self, _val) # return Vector2i_divide_vector(self, _val)
{{ render_property("x", "get_x", "set_x") | indent }} {{ render_property("x", "get_x", "set_x") | indent }}
{{ render_property("y", "get_y", "set_y") | 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_add", py_name="__add__") | indent }}
{{ render_method("operator_subtract", py_name="__sub__") | indent }} {{ render_method("operator_subtract", py_name="__sub__") | indent }}
def __mul__(Vector3i self, val): #def __mul__(Vector3i self, val):
cdef Vector3i _val # cdef Vector3i _val
try: # try:
_val = <Vector3i?>val # _val = <Vector3i?>val
except TypeError: # except TypeError:
return Vector3i_multiply_scalar(self, val) # return Vector3i_multiply_scalar(self, val)
else: # else:
return Vector3i_multiply_vector(self, _val) # return Vector3i_multiply_vector(self, _val)
def __truediv__(Vector3i self, val): #def __truediv__(Vector3i self, val):
cdef Vector3i _val # cdef Vector3i _val
try: # try:
_val = <Vector3i?>val # _val = <Vector3i?>val
except TypeError: # except TypeError:
if val is 0: # if val is 0:
raise ZeroDivisionError() # raise ZeroDivisionError()
return Vector3i_divide_scalar(self, val) # return Vector3i_divide_scalar(self, val)
else: # else:
if _val.x == 0 or _val.y == 0 or _val.z == 0: # if _val.x == 0 or _val.y == 0 or _val.z == 0:
raise ZeroDivisionError() # raise ZeroDivisionError()
return Vector3i_divide_vector(self, _val) # return Vector3i_divide_vector(self, _val)
{{ render_method("as_string") | indent }} {{ render_method("as_string") | indent }}
{% endblock %} {% endblock %}

View File

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

View File

@ -48,9 +48,9 @@ from pandemonium.tags import ExportedField, SignalField
cdef inline pandemonium_pluginscript_script_manifest _build_empty_script_manifest(): cdef inline pandemonium_pluginscript_script_manifest _build_empty_script_manifest():
cdef pandemonium_pluginscript_script_manifest manifest cdef pandemonium_pluginscript_script_manifest manifest
manifest.data = NULL manifest.data = NULL
gdapi10.pandemonium_string_name_new_data(&manifest.name, "") gdapi10.pandemonium_string_name_new_data_char(&manifest.name, "")
manifest.is_tool = False 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_dictionary_new(&manifest.member_lines)
gdapi10.pandemonium_array_new(&manifest.methods) gdapi10.pandemonium_array_new(&manifest.methods)
gdapi10.pandemonium_array_new(&manifest.signals) gdapi10.pandemonium_array_new(&manifest.signals)

View File

@ -1,5 +1,9 @@
from libc.stddef cimport wchar_t from libc.stddef cimport wchar_t
from libc.stdio cimport printf 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.gdapi cimport pythonscript_gdapi10 as gdapi10
from pandemonium._hazmat.gdnative_api_struct cimport ( 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): cdef inline str pandemonium_string_to_pyobj(const pandemonium_string *p_gdstr):
# TODO: unicode&windows support is most likely broken... # 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) cdef pandemonium_int length = gdapi10.pandemonium_string_length(p_gdstr)
return raw[:length * _STRING_CODEPOINT_LENGTH].decode(_STRING_ENCODING) 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) # cdef pandemonium_int length = gdapi10.pandemonium_string_length(p_gdstr)
# printf("==========> pandemonium_string_to_pyobj ") # printf("==========> pandemonium_string_to_pyobj ")
# cdef int i # 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): cdef inline void pyobj_to_pandemonium_string(str pystr, pandemonium_string *p_gdstr):
# TODO: unicode&windows support is most likely broken... # TODO: unicode&windows support is most likely broken...
cdef bytes raw = pystr.encode(_STRING_ENCODING) cdef bytes raw = pystr.encode(_STRING_ENCODING)
gdapi10.pandemonium_string_new_with_wide_string( gdapi10.pandemonium_string_newc_clip_to_len(
p_gdstr, (<wchar_t*><char*>raw), len(pystr) 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) gdapi10.pandemonium_string_destroy(&strname)
return ret return ret
cdef inline void pyobj_to_pandemonium_string_name(str pystr, pandemonium_string_name *p_gdname): cdef inline void pyobj_to_pandemonium_string_name(str pystr, pandemonium_string_name *p_gdname):
cdef pandemonium_string strname cdef pandemonium_string strname
pyobj_to_pandemonium_string(pystr, &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) 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 inline Quaternion _pandemonium_variant_to_pyobj_quat(const pandemonium_variant *p_gdvar):
cdef Quaternion ret = Quaternion.__new__(Quaternion) 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 return ret
@ -358,7 +358,7 @@ cdef bint pyobj_to_pandemonium_variant(object pyobj, pandemonium_variant *p_var)
elif isinstance(pyobj, Plane): elif isinstance(pyobj, Plane):
gdapi10.pandemonium_variant_new_plane(p_var, &(<Plane>pyobj)._gd_data) gdapi10.pandemonium_variant_new_plane(p_var, &(<Plane>pyobj)._gd_data)
elif isinstance(pyobj, Quaternion): 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): elif isinstance(pyobj, AABB):
gdapi10.pandemonium_variant_new_aabb(p_var, &(<AABB>pyobj)._gd_data) gdapi10.pandemonium_variant_new_aabb(p_var, &(<AABB>pyobj)._gd_data)
elif isinstance(pyobj, Basis): elif isinstance(pyobj, Basis):

View File

@ -20,246 +20,245 @@
#include "_pandemonium_api.h" #include "_pandemonium_api.h"
static const char *PYTHONSCRIPT_RECOGNIZED_EXTENSIONS[] = { "py", "pyc", "pyo", "pyd", 0 }; static const char *PYTHONSCRIPT_RECOGNIZED_EXTENSIONS[] = { "py", "pyc", "pyo", "pyd", 0 };
static const char *PYTHONSCRIPT_RESERVED_WORDS[] = { static const char *PYTHONSCRIPT_RESERVED_WORDS[] = {
"False", "False",
"None", "None",
"True", "True",
"and", "and",
"as", "as",
"assert", "assert",
"break", "break",
"class", "class",
"continue", "continue",
"def", "def",
"del", "del",
"elif", "elif",
"else", "else",
"except", "except",
"finally", "finally",
"for", "for",
"from", "from",
"global", "global",
"if", "if",
"import", "import",
"in", "in",
"is", "is",
"lambda", "lambda",
"nonlocal", "nonlocal",
"not", "not",
"or", "or",
"pass", "pass",
"raise", "raise",
"return", "return",
"try", "try",
"while", "while",
"with", "with",
"yield", "yield",
0 0
}; };
static const char *PYTHONSCRIPT_COMMENT_DELIMITERS[] = { "#", "\"\"\"\"\"\"", 0 }; static const char *PYTHONSCRIPT_COMMENT_DELIMITERS[] = { "#", "\"\"\"\"\"\"", 0 };
static const char *PYTHONSCRIPT_STRING_DELIMITERS[] = { "\" \"", "' '", 0 }; static const char *PYTHONSCRIPT_STRING_DELIMITERS[] = { "\" \"", "' '", 0 };
static pandemonium_pluginscript_language_desc desc; static pandemonium_pluginscript_language_desc desc;
static PyThreadState *gilstate = NULL; static PyThreadState *gilstate = NULL;
/* /*
* Global variables exposing Pandemonium API to the pandemonium.hazmat cython module. * Global variables exposing Pandemonium API to the pandemonium.hazmat cython module.
* Hence we must initialized them before loading `_pandemonium`/`pandemonium` modules * Hence we must initialized them before loading `_pandemonium`/`pandemonium` modules
* (which both depend on `pandemonium.hazmat`). * (which both depend on `pandemonium.hazmat`).
*/ */
#ifdef _WIN32 #ifdef _WIN32
# define PYTHONSCRIPT_EXPORT __declspec(dllexport) #define PYTHONSCRIPT_EXPORT __declspec(dllexport)
#else #else
# define PYTHONSCRIPT_EXPORT #define PYTHONSCRIPT_EXPORT
#endif #endif
PYTHONSCRIPT_EXPORT const pandemonium_gdnative_core_api_struct *pythonscript_gdapi10 = NULL; PYTHONSCRIPT_EXPORT const pandemonium_gdnative_core_api_struct *pythonscript_gdapi10 = NULL;
PYTHONSCRIPT_EXPORT const pandemonium_gdnative_ext_nativescript_api_struct *pythonscript_gdapi_ext_nativescript = NULL; PYTHONSCRIPT_EXPORT const pandemonium_gdnative_ext_nativescript_api_struct *pythonscript_gdapi_ext_nativescript = NULL;
PYTHONSCRIPT_EXPORT const pandemonium_gdnative_ext_pluginscript_api_struct *pythonscript_gdapi_ext_pluginscript = NULL; 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; PYTHONSCRIPT_EXPORT const pandemonium_gdnative_ext_android_api_struct *pythonscript_gdapi_ext_android = NULL;
static void _register_gdapi(const pandemonium_gdnative_init_options *options) { static void _register_gdapi(const pandemonium_gdnative_init_options *options) {
pythonscript_gdapi10 = (const pandemonium_gdnative_core_api_struct *)options->api_struct; pythonscript_gdapi10 = (const pandemonium_gdnative_core_api_struct *)options->api_struct;
/* /*
if (pythonscript_gdapi10->next) { if (pythonscript_gdapi10->next) {
pythonscript_gdapi11 = (const pandemonium_gdnative_core_1_1_api_struct *)pythonscript_gdapi10->next; pythonscript_gdapi11 = (const pandemonium_gdnative_core_1_1_api_struct *)pythonscript_gdapi10->next;
if (pythonscript_gdapi11->next) { if (pythonscript_gdapi11->next) {
pythonscript_gdapi12 = (const pandemonium_gdnative_core_1_2_api_struct *)pythonscript_gdapi11->next; pythonscript_gdapi12 = (const pandemonium_gdnative_core_1_2_api_struct *)pythonscript_gdapi11->next;
} }
} }
*/ */
for (unsigned int i = 0; i < pythonscript_gdapi10->num_extensions; i++) { for (unsigned int i = 0; i < pythonscript_gdapi10->num_extensions; i++) {
const pandemonium_gdnative_api_struct *ext = pythonscript_gdapi10->extensions[i]; const pandemonium_gdnative_api_struct *ext = pythonscript_gdapi10->extensions[i];
switch (ext->type) { switch (ext->type) {
case GDNATIVE_EXT_NATIVESCRIPT: case GDNATIVE_EXT_NATIVESCRIPT:
pythonscript_gdapi_ext_nativescript = (const pandemonium_gdnative_ext_nativescript_api_struct *)ext; pythonscript_gdapi_ext_nativescript = (const pandemonium_gdnative_ext_nativescript_api_struct *)ext;
break; break;
case GDNATIVE_EXT_PLUGINSCRIPT: case GDNATIVE_EXT_PLUGINSCRIPT:
pythonscript_gdapi_ext_pluginscript = (const pandemonium_gdnative_ext_pluginscript_api_struct *)ext; pythonscript_gdapi_ext_pluginscript = (const pandemonium_gdnative_ext_pluginscript_api_struct *)ext;
break; break;
case GDNATIVE_EXT_ANDROID: case GDNATIVE_EXT_ANDROID:
pythonscript_gdapi_ext_android = (const pandemonium_gdnative_ext_android_api_struct *)ext; pythonscript_gdapi_ext_android = (const pandemonium_gdnative_ext_android_api_struct *)ext;
break; break;
default: default:
break; break;
} }
} }
} }
GDN_EXPORT void pandemonium_gdnative_init(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 ! // Registering the api should be the very first thing to do !
_register_gdapi(options); _register_gdapi(options);
// Now those macros are usable // 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( \ pandemonium_string gd_msg; \
&gd_msg, c_msg, -1); \ pythonscript_gdapi10->pandemonium_string_new_with_wide_string( \
pythonscript_gdapi10->pandemonium_print(&gd_msg); \ &gd_msg, c_msg, -1); \
pythonscript_gdapi10->pandemonium_string_destroy(&gd_msg); \ pythonscript_gdapi10->pandemonium_print(&gd_msg); \
} 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__); \ { \
} pythonscript_gdapi10->pandemonium_print_error(msg, __func__, __FILE__, __LINE__); \
}
// Check for mandatory plugins // Check for mandatory plugins
/* /*
if (!pythonscript_gdapi10 || !pythonscript_gdapi11 || !pythonscript_gdapi12) { if (!pythonscript_gdapi10 || !pythonscript_gdapi11 || !pythonscript_gdapi12) {
GD_ERROR_PRINT("Pandemonium-Python requires GDNative API >= v1.2"); GD_ERROR_PRINT("Pandemonium-Python requires GDNative API >= v1.2");
return; return;
} }
*/ */
if (!pythonscript_gdapi_ext_pluginscript) { if (!pythonscript_gdapi_ext_pluginscript) {
GD_ERROR_PRINT("Pluginscript extension not available"); GD_ERROR_PRINT("Pluginscript extension not available");
return; return;
} }
#ifndef _WIN32 #ifndef _WIN32
// Make sure the shared library has all it symbols loaded // Make sure the shared library has all it symbols loaded
// (strange bug with libpython3.x.so otherwise...) // (strange bug with libpython3.x.so otherwise...)
{ {
const wchar_t *wpath = pythonscript_gdapi10->pandemonium_string_wide_str( pandemonium_char_16_string wpstr = pythonscript_gdapi10->pandemonium_string_utf16(options->active_library_path);
options->active_library_path const wchar_t *wpath = (wchar_t *)pythonscript_gdapi10->pandemonium_char_16_string_get_data(&wpstr);
);
char path[300];
wcstombs(path, wpath, 300);
dlopen(path, RTLD_NOW | RTLD_GLOBAL);
}
const char *err = dlerror(); //const wchar_t *wpath = pythonscript_gdapi10->pandemonium_string_wide_str(
if (err) { // options->active_library_path
GD_ERROR_PRINT(err); //);
return; char path[300];
} wcstombs(path, wpath, 300);
dlopen(path, RTLD_NOW | RTLD_GLOBAL);
}
const char *err = dlerror();
if (err) {
GD_ERROR_PRINT(err);
return;
}
#endif #endif
// Initialize CPython interpreter // Initialize CPython interpreter
// Retrieve path and set pythonhome // Retrieve path and set pythonhome
{ {
static wchar_t pythonhome[300]; static wchar_t pythonhome[300];
pandemonium_string _pythonhome = pythonscript_gdapi10->pandemonium_string_get_base_dir( pandemonium_string _pythonhome = pythonscript_gdapi10->pandemonium_string_get_base_dir(
options->active_library_path options->active_library_path);
);
wcsncpy(pythonhome, pythonscript_gdapi10->pandemonium_string_wide_str(&_pythonhome), 300);
pythonscript_gdapi10->pandemonium_string_destroy(&_pythonhome);
Py_SetPythonHome(pythonhome);
}
// TODO: site.USER_SITE seems to point to an invalid location in ~/.local
// // Add current dir to PYTHONPATH
// wchar_t *path = Py_GetPath();
// int new_path_len = wcslen(path) + 3;
// wchar_t new_path[new_path_len * sizeof(wchar_t)];
// wcsncpy(new_path, L".:", new_path_len);
// wcsncpy(new_path + 2, path, new_path_len - 2);
// Py_SetPath(new_path);
// PyRun_SimpleString("import sys\nprint('PYTHON_PATH:', sys.path)\n");
Py_SetProgramName(L"pandemonium"); pandemonium_char_16_string wpstr = pythonscript_gdapi10->pandemonium_string_utf16(&_pythonhome);
// Initialize interpreter but skip initialization registration of signal handlers wcsncpy(pythonhome, (wchar_t *)pythonscript_gdapi10->pandemonium_char_16_string_get_data(&wpstr), 300);
Py_InitializeEx(0); pythonscript_gdapi10->pandemonium_string_destroy(&_pythonhome);
// PyEval_InitThreads acquires the GIL, so we must release it later. Py_SetPythonHome(pythonhome);
// Since python3.7 PyEval_InitThreads is automatically called by Py_InitializeEx, but it's better to leave it here }
// to be explicit. Calling it again does nothing. // TODO: site.USER_SITE seems to point to an invalid location in ~/.local
PyEval_InitThreads(); // // Add current dir to PYTHONPATH
int ret = import__pandemonium(); // wchar_t *path = Py_GetPath();
if (ret != 0){ // int new_path_len = wcslen(path) + 3;
GD_ERROR_PRINT("Cannot load pandemonium python module"); // wchar_t new_path[new_path_len * sizeof(wchar_t)];
return; // wcsncpy(new_path, L".:", new_path_len);
} // wcsncpy(new_path + 2, path, new_path_len - 2);
// Py_SetPath(new_path);
// PyRun_SimpleString("import sys\nprint('PYTHON_PATH:', sys.path)\n");
desc.name = "Python"; Py_SetProgramName(L"pandemonium");
desc.type = "Python"; // Initialize interpreter but skip initialization registration of signal handlers
desc.extension = "py"; Py_InitializeEx(0);
desc.recognized_extensions = PYTHONSCRIPT_RECOGNIZED_EXTENSIONS; // PyEval_InitThreads acquires the GIL, so we must release it later.
desc.init = pythonscript_init; // Since python3.7 PyEval_InitThreads is automatically called by Py_InitializeEx, but it's better to leave it here
desc.finish = pythonscript_finish; // to be explicit. Calling it again does nothing.
desc.reserved_words = PYTHONSCRIPT_RESERVED_WORDS; PyEval_InitThreads();
desc.comment_delimiters = PYTHONSCRIPT_COMMENT_DELIMITERS; int ret = import__pandemonium();
desc.string_delimiters = PYTHONSCRIPT_STRING_DELIMITERS; if (ret != 0) {
desc.has_named_classes = false; GD_ERROR_PRINT("Cannot load pandemonium python module");
desc.add_global_constant = pythonscript_add_global_constant; return;
}
desc.script_desc.init = pythonscript_script_init; desc.name = "Python";
desc.script_desc.finish = pythonscript_script_finish; desc.type = "Python";
desc.extension = "py";
desc.recognized_extensions = PYTHONSCRIPT_RECOGNIZED_EXTENSIONS;
desc.init = pythonscript_init;
desc.finish = pythonscript_finish;
desc.reserved_words = PYTHONSCRIPT_RESERVED_WORDS;
desc.comment_delimiters = PYTHONSCRIPT_COMMENT_DELIMITERS;
desc.string_delimiters = PYTHONSCRIPT_STRING_DELIMITERS;
desc.has_named_classes = false;
desc.add_global_constant = pythonscript_add_global_constant;
desc.script_desc.instance_desc.init = pythonscript_instance_init; desc.script_desc.init = pythonscript_script_init;
desc.script_desc.instance_desc.finish = pythonscript_instance_finish; desc.script_desc.finish = pythonscript_script_finish;
desc.script_desc.instance_desc.set_prop = pythonscript_instance_set_prop;
desc.script_desc.instance_desc.get_prop = pythonscript_instance_get_prop;
desc.script_desc.instance_desc.call_method = pythonscript_instance_call_method;
desc.script_desc.instance_desc.notification = pythonscript_instance_notification;
desc.script_desc.instance_desc.refcount_incremented = NULL;
desc.script_desc.instance_desc.refcount_decremented = NULL;
if (options->in_editor) { desc.script_desc.instance_desc.init = pythonscript_instance_init;
desc.script_desc.instance_desc.finish = pythonscript_instance_finish;
desc.script_desc.instance_desc.set_prop = pythonscript_instance_set_prop;
desc.script_desc.instance_desc.get_prop = pythonscript_instance_get_prop;
desc.script_desc.instance_desc.call_method = pythonscript_instance_call_method;
desc.script_desc.instance_desc.notification = pythonscript_instance_notification;
desc.script_desc.instance_desc.refcount_incremented = NULL;
desc.script_desc.instance_desc.refcount_decremented = NULL;
desc.get_template_source_code = pythonscript_get_template_source_code; if (options->in_editor) {
desc.validate = pythonscript_validate; desc.get_template_source_code = pythonscript_get_template_source_code;
desc.find_function = pythonscript_find_function; desc.validate = pythonscript_validate;
desc.make_function = pythonscript_make_function; desc.find_function = pythonscript_find_function;
desc.complete_code = pythonscript_complete_code; desc.make_function = pythonscript_make_function;
desc.auto_indent_code = pythonscript_auto_indent_code; desc.complete_code = pythonscript_complete_code;
desc.auto_indent_code = pythonscript_auto_indent_code;
desc.debug_get_error = pythonscript_debug_get_error; desc.debug_get_error = pythonscript_debug_get_error;
desc.debug_get_stack_level_count = pythonscript_debug_get_stack_level_count; desc.debug_get_stack_level_count = pythonscript_debug_get_stack_level_count;
desc.debug_get_stack_level_line = pythonscript_debug_get_stack_level_line; desc.debug_get_stack_level_line = pythonscript_debug_get_stack_level_line;
desc.debug_get_stack_level_function = pythonscript_debug_get_stack_level_function; desc.debug_get_stack_level_function = pythonscript_debug_get_stack_level_function;
desc.debug_get_stack_level_source = pythonscript_debug_get_stack_level_source; desc.debug_get_stack_level_source = pythonscript_debug_get_stack_level_source;
desc.debug_get_stack_level_locals = pythonscript_debug_get_stack_level_locals; desc.debug_get_stack_level_locals = pythonscript_debug_get_stack_level_locals;
desc.debug_get_stack_level_members = pythonscript_debug_get_stack_level_members; desc.debug_get_stack_level_members = pythonscript_debug_get_stack_level_members;
desc.debug_get_globals = pythonscript_debug_get_globals; desc.debug_get_globals = pythonscript_debug_get_globals;
desc.debug_parse_stack_level_expression = pythonscript_debug_parse_stack_level_expression; desc.debug_parse_stack_level_expression = pythonscript_debug_parse_stack_level_expression;
desc.profiling_start = pythonscript_profiling_start; desc.profiling_start = pythonscript_profiling_start;
desc.profiling_stop = pythonscript_profiling_stop; desc.profiling_stop = pythonscript_profiling_stop;
desc.profiling_get_accumulated_data = pythonscript_profiling_get_accumulated_data; desc.profiling_get_accumulated_data = pythonscript_profiling_get_accumulated_data;
desc.profiling_get_frame_data = pythonscript_profiling_get_frame_data; desc.profiling_get_frame_data = pythonscript_profiling_get_frame_data;
desc.profiling_frame = pythonscript_profiling_frame; desc.profiling_frame = pythonscript_profiling_frame;
} }
pythonscript_gdapi_ext_pluginscript->pandemonium_pluginscript_register_language(&desc); pythonscript_gdapi_ext_pluginscript->pandemonium_pluginscript_register_language(&desc);
// Release the Kraken... er I mean the GIL ! // Release the Kraken... er I mean the GIL !
gilstate = PyEval_SaveThread(); gilstate = PyEval_SaveThread();
} }
GDN_EXPORT void pandemonium_gdnative_singleton() { GDN_EXPORT void pandemonium_gdnative_singleton() {
} }
GDN_EXPORT void pandemonium_gdnative_terminate() { GDN_EXPORT void pandemonium_gdnative_terminate() {
// Re-acquire the gil in order to finalize properly // Re-acquire the gil in order to finalize properly
PyEval_RestoreThread(gilstate); PyEval_RestoreThread(gilstate);
int ret = Py_FinalizeEx(); int ret = Py_FinalizeEx();
if (ret != 0) { if (ret != 0) {
GD_ERROR_PRINT("Cannot finalize python interpreter"); GD_ERROR_PRINT("Cannot finalize python interpreter");
} }
} }