enumerations and tolua

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

enumerations and tolua

Supratik Champati
Hi Everyone,

I have two issues -

1. tolua is having problems parsing stuff like -

enum Choice {
	ch1 = 0,
	ch2 = 1
};

If I have an enum declared inside a class it has a
problems as well.

Is there a way around the above or do I need source code changes?
If it is the latter I would really appreciate any suggestions
as to how to go about it.


2. I have a class with 2 overloaded member functions which have
the same name but take different arguments - one takes
an int and another const char *.

class A {
    A();
    ~A();
    void f1(int i);
    void f1(const char *s);
};

If I run the following script the second f1 is getting called where
as the first one should be called.

local aobj = A:new()
local i = 0
aobj:f1(i)
aobj:delete()

Is this a bug or something that is intended and I need to work around it
?


I will appreciate any help.

Thanx in advance.

-- 
Supratik

Reply | Threaded
Open this post in threaded view
|

Re: enumerations and tolua

Waldemar Celes-3
> 1. tolua is having problems parsing stuff like -
> 
> enum Choice {
>         ch1 = 0,
>         ch2 = 1
> };
> 
> If I have an enum declared inside a class it has a
> problems as well.

sorry! tolua is only parsing C-like enumeration.
enum {
      ch1 = 0,
      ch2 = 0
};

I will fix it.


> 2. I have a class with 2 overloaded member functions which have
> the same name but take different arguments - one takes
> an int and another const char *.
> 
> class A {
>     A();
>     ~A();
>     void f1(int i);
>     void f1(const char *s);
> };
> 
> If I run the following script the second f1 is getting called where
> as the first one should be called.
> 
> local aobj = A:new()
> local i = 0
> aobj:f1(i)
> aobj:delete()
> 

that's because, in general, lua converts a string into a number
and vice-versa. in some situations, it is the right choice, but
I agree that here we have a problem.

One simple solution would be to invert the order you declare the
function in the .pkg. As tolua tries the last one first,
it would call the int version when the argument is a number.

you are gonna have a similar problem if you call:

aobj:f1("1")

but, here, the string must be "numeric".

I will think about a fix.

thanks for reporting these problems.

-- waldemar