Announcement

Collapse
No announcement yet.

Alien module structs

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Alien module structs

    I have the following structs on C++ (h file):

    PHP Code:
    struct CCount
        
    {
          
    unsigned longcountLines;
          
    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
        
    {
          
    CCountpCounts;
          
    int nCounts;
          
    int nMaxCounts;
          
    int nMaxLines;

          
    CCounts(int maxCountsint maxLines)
          {
            
    pCounts = new CCount[maxCounts];
            for(
    int i=0i<maxCountsi++)
            {
              
    pCounts[i].countLines = new unsigned long[maxLines];
              
    pCounts[i].maxLines maxLines;
            }
            
    nCounts 0;
            
    nMaxCounts maxCounts;
            
    nMaxLines maxLines;
          }
          ~
    CCounts()
          {
            
    delete[] pCounts;
          }
        }; 
    And, on the other side (lua) i'm using the alien module to define the structs like this:

    PHP Code:
    CCounts alien.defstruct{
      {
    'pCounts''pointer'},
      {
    'nCounts''int'},
      {
    'nMaxCounts''int'},
      {
    'nMaxLines''int'}
    }

    CCount alien.defstruct{
      {
    'countLines''ulong'},
      {
    'numCountLines''int'},
      {
    'maxLines''int'},
      {
    'countTime''ulong'}
    }; 
    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:

    PHP Code:
    pCounts = new CCount[maxCounts];
            for(
    int i=0i<maxCountsi++)
            {
              
    pCounts[i].countLines = new unsigned long[maxLines];
              
    pCounts[i].maxLines maxLines;
            } 
    The pCounts attribute is a CCount instance, and the for loop indicates that the CCount object is indexable. Should the CCount struct be different?
Working...
X