lua-users home
lua-l archive

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

hi David,

> 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]);

Well, it might be a wrong design decision, but it's not a bug.
For tolua, char* represents string while 
char[] represent array of numeric values (varying from 0 to 255). 

> (The below tolua generated binding function
> has the corrections.)  

The corrections you made are not correct :-(

> type[i] = ((unsigned char)  tolua_getfieldstring(lo,i+1,0));

"tolua_getfieldstring" returns a char* not a char.

> I think tolua needs to consider the array type in this
> situation.

Sorry, but for now I prefer to have both approaches: 
string (char*) and array of bytes (char[]).

you can also use the lua functions "strbyte" and "strchar" to
convert from numeric array to string and vice-versa.

> 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)
Yes! You can do that.
Assuming 'err' and 'type' are integers and 'creator' is a string,
you should write in the .pkg file:

int getfileinfo (file_info* fi, int* type=0, char** creator=0);

the use of default values for type and creator allows you not to
pass them when calling the function.

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

thank you for your interest in tolua. hope it can help you.


-- waldemar