Hi,
I am developing one object called py4pd to allow me to load some Python functions as objects (very similar to py/pyext). I have one problem with class_setsavefn, because I need something similar to #X declare -lib mylibrary (an extra line in a specific place in the PureData Patch file) to load the Python functions before pd tries to load the Python objects that are added by the Python module (called pd).
``` py
import pd
def mygreatfunction(x, y)
somegreatthing(x, y)
def py4pdLoadObjects():
pd.addobject(mygreatfunction, "py.greatfunction")
```
To do that, I am working with this function linkhttps://github.com/charlesneimog/py4pd/blob/a49dd8b1c28e3162a45a805781f7cac31197c347/src/py4pd.c#L1641. It works in some cases, but I have problems with undo and redo and a lot of instabilities with specific actions.
https://github.com/charlesneimog/py4pd/blob/a49dd8b1c28e3162a45a805781f7cac3...
Question:
Someone already had to add some extra lines in the pd patch in some specific order?
What is the right way to do it?
One observation: I am adding one new canvas_class method called py4pdLibrary, it loads the Python Library (the objects).
Thank you very much!
________________________ Charles K. Neimog | www.charlesneimog.comhttps://www.charlesneimog.com/ | Universidade de São Paulo
Am 27. April 2023 01:25:06 MESZ schrieb "Charles K. Neimog" charlesneimog@outlook.com:
Hi,
I have one problem with class_setsavefn, because I need something similar to #X declare -lib mylibrary (an extra line in a specific place in the PureData Patch file) to load the Python functions before pd tries to load the Python objects that are added by the Python module (called pd).
[...]
Question:
Someone already had to add some extra lines in the pd patch in some specific order? What is the right way to do it?
One observation: I am adding one new canvas_class method called py4pdLibrary, it loads the Python Library (the objects).
That sounds all wrong. I'm not exactly sure what you are trying to achieve, but most likely fiddling with the internals of the patch representation and adding methods to the canvas is not a good idea (for starters it will create very weird errors if your library cannot be loaded).
Here's what I would do - check whether the relevant Phyton code has been loaded before instantiating the new object ( in the object's constructor (the C-wrapper part thereof) - create a loader with `sys_register_loader`
mfg.sfg.jfd IOhannes