lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Hi Waldemar:

>I was assuming you had included a funtion like:
>file_into * create_file_info(...);

Yes, you are correct, I was not sure that we were talking about the same
thing.  I now understand the issues discussed.  Thank you very much for your
time and assistance.

// BUG REPORT:
It appears that I may have found a bug or problem with regard to arrays in
function parameters.  For example:

short getfileinfo(file_info *zfile,unsigned char type[5],unsigned char
creator[5]);

In tolua, the unsigned char array is assumed to be numeric, which obviously
causes problems with char arrays.  (The below tolua generated binding function
has the corrections.)  I think tolua needs to consider the array type in this
situation.


// COMMENT:
More importantly, is the following the only way for tolua to recognize
multiple return values?  What I want to do is this:

err,type,creator = getfileinfo(fi)
print(type)
print(creator)

instead I have to do this:

type={}
creator={}
err = getfileinfo(fi,type,creator)
print(type[1])
print(creator[1])

I don't need to to pass type and creator information into my C code.  It only
needs to be sent out.  Is there a way to set the .pkg file or "tell" tolua
that this is what is required.  It may not be possible...

Thanks again for your help.  I haven't test everything about tolua yet, but
things are progressing.

Warm Regards,

David

--------------------------------------------
/* function: getfileinfo */
static void toluaI_getfileinfo0(void)
{
 if (
     !tolua_istype(1,tolua_tag_file_info,0) ||
     !tolua_istype(2,tolua_tag_table,0) ||
     !tolua_istype(3,tolua_tag_table,0) ||
     !tolua_isnoobj(4)
 )
  goto error;
 else
 {
  file_info* zfile = ((file_info*)  tolua_getusertype(1,0));
  unsigned char type[5];
  unsigned char creator[5];
  {
   if (!tolua_arrayistype(2,tolua_tag_number,5,1))
    goto error;
   else
   {
    int i;
    lua_Object lo = lua_getparam(2);
    for(i=0; i<5;i++)
     type[i] = ((unsigned char)  tolua_getfieldstring(lo,i+1,0));
     //type[i] = ((unsigned char)  tolua_getfieldnumber(lo,i+1,0)); //
original
   }
  }
  {
   if (!tolua_arrayistype(3,tolua_tag_number,5,1))
    goto error;
   else
   {
    int i;
    lua_Object lo = lua_getparam(3);
    for(i=0; i<5;i++)
     creator[i] = ((unsigned char)  tolua_getfieldstring(lo,i+1,0));
     //creator[i] = ((unsigned char)  tolua_getfieldnumber(lo,i+1,0)); //
original
   }
  }
  {
   short toluaI_ret = getfileinfo(zfile,type,creator);
   tolua_pushnumber((double)toluaI_ret);
  }
  {
   int i;
   lua_Object lo = lua_getparam(2);
   for(i=0; i<5;i++)
   	tolua_pushfieldstring(lo,i+1,(char*) &type[i]);
   //tolua_pushfieldnumber(lo,i+1,(double) type[i]); // original
  }
  {
   int i;
   lua_Object lo = lua_getparam(3);
   for(i=0; i<5;i++)
    tolua_pushfieldstring(lo,i+1,(char*) &creator[i]);
   //tolua_pushfieldnumber(lo,i+1,(double) creator[i]); // original
  }
 }
 return;
error:
 tolua_error("#ferror in function 'getfileinfo'.");
}


Here are some casting problems also (they may be compiler related however):

/* get function: myFileName of class  file_info */
static void toluaI_get_file_info_myFileName(void)
{
  // original:
  //const unsigned file_info* self = (const unsigned file_info*)
tolua_getusertype(1,0);
  // changed to:
  file_info* self = (file_info*)  tolua_getusertype(1,0);
  if (!self) tolua_error("invalid 'self' in accessing variable 'myFileName'");
  // original:
  //tolua_pushstring(self->myFileName);
  // changed to:
  tolua_pushstring((const char*)self->myFileName);
}

/* get function: myFilePath of class  file_info */
static void toluaI_get_file_info_myFilePath(void)
{
   // original:
  //const unsigned file_info* self = (const unsigned file_info*)
tolua_getusertype(1,0);
// changed to:
  file_info* self = (file_info*)  tolua_getusertype(1,0);
  if (!self) tolua_error("invalid 'self' in accessing variable 'myFilePath'");
  //tolua_pushstring(self->myFilePath);
// changed to:
  tolua_pushstring((const char*)self->myFilePath);
}