lua-users home
lua-l archive

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


Ariel Manzur wrote:

> Hi..
> 
> tolua++ doesn't force you to use c++, you can parse/bind C code with it..

ok ok, I just understood :p

> Also, unions usually work OK when binded as structs (or left out of the
> union block, when it's anonymous), why do you want to change it to union?

The problem IS that SDL_Event was binded as a struct ! And in the real code
(SDL is a C library) the management of the SDL_Event type was made with
implicit assertions about its "union nature". Now that it is binded as a
struct, the fields which would have been are not updated anymore !

I explain. SDL_Event structure is the following (in the original SDL.h)

/* General event structure */
typedef union {
        Uint8 type;
        SDL_ActiveEvent active;
        SDL_KeyboardEvent key;
 /* ... lots of events more */ 
} SDL_Event;

What you must know is that SDL_ActiveEvent and SDL_KeyboardEvent which are
"typedef struct" both have a first field which is called "type" and which
is of type "Uint8".

So, in your code, when you have a SDL_Event "e", you can make this (and it
is done like this in hundreds of lines of code) :
if (e.type == SDL_KEYDOWN || e.type == SDL_KEYUP)
{
  manage_key (e.key);   // this function does something with the key event
}
else
{
  // go on with the tests
}

Of course, you can use "switch .. case" statements but its not the purpose
of the discussion here.

manage_key() will have to react to the fact that it is a key pressed or
released and so, it will look into SDL_KeyboardEvent.type field which is,
thanks to the "union system", the same as the SDL_Event.type field.

Am I clearer ? I know that when I don't explain it is hard to understand
me :p


> Ariel.
> 
> At 04:18 PM 3/17/2004, you wrote:
>>The problem is that I don't want to complexify the project by using
>>SDL + SDL -> C++ wrappers + tolua ++ + lua
>>instead of SDL + tolua + lua.
>>
>>Eventually if the problem cannot be solved, than I will really consider it
>>as a solution.
>>
>>
>>Nick Trout wrote:
>>
>> >
>> >> Although I tried many times already, I cannot get into contact with
>> > the
>> >> toLua maintainer whose identity I am not sure of.
>> >
>> > Tolua is no longer maintained. Try using tolua++. You can find a link
>> > off the wiki addons.
>> >
>> > Nick
>>
>>--
>>Chucky
> 
> Ariel.
> http://Anime.com.ar
> snm

-- 
Chucky