I have the following structs on C++ (h file):
And, on the other side (lua) i'm using the alien module to define the structs like this:
I know I can't define (for now) the default struct "__construct" callbacks (like setting default values for nMaxCounts, etc), so I'm doing it after create the struct object. My problem is at the "CCount" struct when I create a new "CCounts" struct, because I don't know how to replicate this callback:
The pCounts attribute is a CCount instance, and the for loop indicates that the CCount object is indexable. Should the CCount struct be different?
PHP Code:
struct CCount
{
unsigned long* countLines;
int numCountLines;
int maxLines;
unsigned long countTime;
CCount()
{
countLines = NULL;
numCountLines = 0;
maxLines = 0;
countTime = 0;
}
CCount(int nMaxLines)
{
countLines = new unsigned long[nMaxLines];
numCountLines = 0;
maxLines = nMaxLines;
countTime = 0;
}
~CCount()
{
delete[] countLines;
}
};
struct CCounts
{
CCount* pCounts;
int nCounts;
int nMaxCounts;
int nMaxLines;
CCounts(int maxCounts, int maxLines)
{
pCounts = new CCount[maxCounts];
for(int i=0; i<maxCounts; i++)
{
pCounts[i].countLines = new unsigned long[maxLines];
pCounts[i].maxLines = maxLines;
}
nCounts = 0;
nMaxCounts = maxCounts;
nMaxLines = maxLines;
}
~CCounts()
{
delete[] pCounts;
}
};
PHP Code:
CCounts = alien.defstruct{
{'pCounts', 'pointer'},
{'nCounts', 'int'},
{'nMaxCounts', 'int'},
{'nMaxLines', 'int'}
}
CCount = alien.defstruct{
{'countLines', 'ulong'},
{'numCountLines', 'int'},
{'maxLines', 'int'},
{'countTime', 'ulong'}
};
PHP Code:
pCounts = new CCount[maxCounts];
for(int i=0; i<maxCounts; i++)
{
pCounts[i].countLines = new unsigned long[maxLines];
pCounts[i].maxLines = maxLines;
}