Skip to content
adambiser edited this page Dec 20, 2017 · 1 revision

About

This plugin provides access to common Python capabilities that are compatible with AGK's Tier 1 programming as well as the ability to utilize AGK's capabilities from inside Python scripts.

Installing the Plugin

  1. Add the Plugin to the AGK IDE. Copy the PythonPlugin folder from inside the AGKPlugin folder of this repository into the "Tier 1\Compiler\Plugins" folder where App Game Kit 2 is installed on your system.
  2. Your project folder will also need the following files in order to work. These files can be found in any of the example projects in this repository.
    • python3.dll
    • python36.dll
    • python36.zip

The AGK site has a complete guide to creating, installing, and using AGK plugins that you might find useful if you're new to them.

PyObject* Returns and Parameters

Since AGK code cannot handle plugin functions that return PyObjects, a handle to a PyObject pointer is returned instead. This value is a 1-based integer and is also used for functions that have PyObject parameters in embedded Python. While it would have been possible to return the PyObject pointer values themselves, these handles are safer to use. The plugin maintains an internal list of PyObject pointers and the handle is just an index within the list. Each new or borrowed reference has a unique handle, so do not compare the handles to see if the PyObjects are the same!

References

Python uses reference counts to know when objects can be deleted. Almost every command that returns a PyObject handle has created a new reference that also needs to have its count decremented with Py_DECREF when the reference is no longer in use.

Exceptions

  • PyDict_GetItem
  • PyList_GetItem
  • Any item handle passed into PyList_SetItem. The list takes control of the item reference.
  • PyTuple_GetItem
  • Any item handle passed into PyTuple_SetItem. The tuple takes control of the item reference.

Command Naming Convention

For the most part, this plugin uses method names that match the names provided by embedded Python.

However, there are a few places where function names differ in order make things easier to do from AGK code.

Embedded Python Name Equivalent Plugin Name Plugin's New Value-Based Helper Command(s)
PyObject_GetAttr
PyObject_GetAttrString
PyObject_GetAttrHandle PyObject_GetAttrFloat
PyObject_GetAttrInt
PyObject_GetAttrString
PyObject_SetAttr
PyObject_SetAttrString
PyObject_SetAttrHandle PyObject_SetAttr (Works with float, integer, and string values.)
PyTuple_GetItem PyTuple_GetItemHandle PyTuple_GetItemFloat
PyTuple_GetItemInt
PyTuple_GetItemString
PyTuple_SetItem PyTuple_SetItemHandle PyTuple_SetItem (Works for float, integer, and string values.)
PyList_GetItem PyList_GetItemHandle PyList_GetItemFloat
PyList_GetItemInt
PyList_GetItemString
PyList_SetItem PyList_SetItemHandle PyList_SetItem (Works for float, integer, and string values.)
PyList_Insert PyList_InsertHandle PyList_Insert (Works for float, integer, and string values.)
PyList_Append PyList_AppendHandle PyList_Append (Works for float, integer, and string values.)
PyDict_GetItem PyDict_GetItemHandle PyDict_GetItemFloat
PyDict_GetItemInt
PyDict_GetItemString
PyDict_SetItem PyDict_SetItemHandle PyDict_SetItem (Works for float, integer, and string values.)
Clone this wiki locally