[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: toLua 5 errors/questions
- From: lukey@... (Jens Hassler)
- Date: 17 Aug 2003 14:33:00 +0200
Hi,
I'm having some difficulties with the new version of toLua.
1. I have these definitions inside my package file:
class gsGlobals {
...
const int activate_extra_bar;
const int activate_extra_bar @ extra_bar;
...
};
The second "extra_bar" is there for compatibility reasons.
toLua wraps "extra_bar" correctly to the "activate_extra_bar"
function:
tolua_variable(tolua_S,"activate_extra_bar", \
tolua_get_gsGlobals_activate_extra_bar,NULL);
tolua_variable(tolua_S,"extra_bar", \
tolua_get_gsGlobals_activate_extra_bar,NULL);
But toLua also creates TWO functions for it:
/* get function: activate_extra_bar of class gsGlobals */
static int tolua_get_gsGlobals_activate_extra_bar(lua_State* tolua_S)
{
...
}
This one is immediately followed by exactly the same function
in the generated C source file causing the compiler to complain
an error.
I have the same problem with another @-function, so I think the
bug has something to do with this.
Or has there something in the .pkg syntax changed from toLua 4
to the new version? toLua 4 worked perfectly.
Note: This only happens in the above case, when two identifiers
relate to the same C function. Other @ declarations work fine.
2. This seems to be a very strange problem. Well, it worked with
Lua 4, so I have to assume there is a "bug"(?) somewhere in Lua or
toLua. Or my code is incorrect, which would be my preferred
solution :)
I have some class instances exported as arrays, such as these
in my .pkg file:
class gsPlayer {
...
};
extern gsPlayer *player[8];
Now, if I do something like...
if player[1] == player[2] then this_never_happens() end
...in my script, there is the following message on stderr:
"attempt to perform operation on an invalid operand"
Well, that would be no problem, cause no one needs to compare two
different user data.
But I have some kind of hook function in my code (nothing to do
with Lua hooks) which is called by the host program when one of
the players die:
function hook_player_dead(pl)
if pl == player[1] then
-- do something with player 1
end
end
This hook function is called by the host program in this way:
lua_pushstring(L, "hook_player_dead");
lua_gettable(L, LUA_GLOBALSINDEX);
tolua_pushusertype(L,(void*)myplayer,"gsPlayer");
lua_call(L, 1, 1);
if (lua_isnumber(L, -1)) ret = (int)lua_tonumber(L, -1);
lua_pop(L, 1);
So "pl" is a valid player structure.
If player[1] dies, the hook function is called and the
if statement seems to work perfectly.
But if player[2] dies, my program just exits without shouting
errors to stderr or somewhere else. Even my debugger says the
program ended correctly, but with errorlevel 1.
All of this worked perfectly with Lua 4.
When using class members in the if statement, e.g. something like...
if pl:get_nr() == player[1]:get_nr() then
end
...everything works perfectly.
So, can anyone point me to the error I hopefully made?
Thank you a lot.
Bye,
Jens