-
Notifications
You must be signed in to change notification settings - Fork 22
Python Extension
Refers to a Python class of objects dubbed "PyObjHandle". These are used for things like game characters and static objects.
The specifications of PyObjHandle are defined in the DLL at 0x102CF3B8
. TemplePlus alters these in order to extend the Python functionality.
Specifically, it replaces the getattr
and setattr
methods, which govern reading from and writing into the object.
To do so, you need to edit the function pyObjHandleType_getAttrNew
.
name
is the attribute name which the python looks up. Example:
obj.map
will run this function (pyObjHandleType_getAttrNew
) with input name = 'map'
.
It is then up to you to do whatever you want with that - you can return a value, or you can return a method (function).
There is actually not a lot of difference between methods and properties. The concept is very similar: you look up a property (e.g. obj.move
), but instead of returning something like a PyInt or PyString, it returns a PyCFunction object. This function can then be executed. So it's really just up to you to return a function.
Example:
obj.location
returns a PyLong object. This is not a function.
obj.destroy
returns a PyCFunction object.
obj.destroy()
simply executes that function!
To create new python methods, you need to add an entry to the struct
static PyMethodDef pyObjHandleMethods_New
And then you should use the function Py_FindMethod
to retrieve and return the message. See various examples inside the file python.cpp
.