Python/C for generatePath

12monkeys

Prince
Joined
Nov 24, 2003
Messages
440
Location
Germany, Europe
I need some help for a specific problem. I try to implement the function CySelectionGroup.genereate(Path) into one of my mods. Here is the Python API definition of the function :

Code:
BOOL generatePath(CyPlot pFromPlot, CyPlot pToPlot, INT iFlags, 
BOOL bReuse, INT piPathTurns)

with the following explanation :

Code:
bool (CyPlot* pFromPlot, CyPlot* pToPlot, int iFlags, 
bool bReuse, int* piPathTurns)

Problem now, is the last parameter "int*". I'm not able to do a call by reference of an int type with Python (or maybe I'm simply to stupid).

So, does anybody know how to do a call by reference of such a standard type?

Alternatively : is anybody able to write a small C lib, which we can import into our Python code, which can be used as an interface for that function?

The definition could be like this :

Code:
int (CyPlot* pFromPlot, CyPlot* pToPlot, int iFlags, bool bReuse, int iPathTurns)

The return parameter is the number of PathTurn. If the function fails, it return -1. This should be an adequate replacement of the former bool return values.

That means, the lib could look like this :

Code:
#include <Python.h>
import CoreLib.DLL  // Civ4 Core Lib DLL. DOn't know if this call is right

int MyGeneratePath(PyObject *pFromPlot, PyObject *pToPlot, int iFlags, bool bReuse, int iPathTurns)
{
   if (generatePath(pFromPlot, pToPlot, iFlags, bReuse, iPathTurns)) {
      return iPathTurns;
   } else {
      return -1;
   }   
}
(Sorry, its quite long ago that I wrote some C, so excuse my syntax and typos)


Is there anybody out there, who is able to write that tiny little lib????

EDIT :
sorry I forgot to mention, that the C function must be a method of the python class CySelectionGroup. I have no clue, how to do that in C.
 
First of all the code you would want would be more like this:
Code:
#include <Python.h>
import CoreLib.DLL  // Civ4 Core Lib DLL. DOn't know if this call is right

int MyGeneratePath(PyObject* self,PyObject *pFromPlot, PyObject *pToPlot, int iFlags, bool bReuse)
{
   int iPathTurns;
   CyUnit *unit = something_cast (self->getCPPClass())
   if (generatePath(pFromPlot, pToPlot, iFlags, bReuse, &iPathTurns)) {
      return iPathTurns;
   } else {
      return -1;
   }   
}
(assuming iPathTurns is just an extra return value), but this wouldn't work without the header files for the core DLL. Even if someone better than me at C++ can get around that, you still need a way of exporting this to the python and finding the getCPPClass method. Better to just wait for the sdk and correct the python exported version of the method there to change the definition.
 
Back
Top Bottom