[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Stack overflow
- From: Sean Middleditch <elanthis@...>
- Date: 02 May 2002 16:37:08 -0400
On Thu, 2002-05-02 at 16:27, Jens Hassler wrote:
> Hi there,
>
> I think this is a typical beginner problem, so I hope someone can give me
> an answer :)
>
> In my C(++) code of my game project I call a hook function defined in the
> Lua code with a handle to a game object (passed via a "tolua" function)
> each time when it is updated:
>
> ------------------------------------------------------------------------
> int do_hook_object_update(Object *o)
> {
> char func[50];
> int retcode = 0;
>
> sprintf(func, "hook_object_update", n);
What is with this line? What is the variable n there? Also, if you're
calling 60 times a second, you'd be a lot better off not bothering with
the buffer/sprintf at all, and instead just doing
lua.getglobal ("hook_object_update");
That'll save on the data shuffling, which on modern processes, tends to
be what bites you in the arse the most, speed wise.
> lua.getglobal(func);
> tolua_pushusertype(lua.get_state(),(void*)o,tolua_tag(lua.get_state(),"Object"));
> lua.call(1, 1);
> if (lua.isnumber(1)) ret = (int)lua.tonumber(1);
>
> return ret;
> }
> ------------------------------------------------------------------------
>
>
> I do this with other events, too (when object is dead, when it is hit, and
> so on), but the code above is called 60 times a second - and this is
> causing a stack overflow after a few seconds.
>
> The lua functions are encapsulated inside a little C++ class I found
> somewhere, so don't mind :)
>
> Am I doing something really nasty wrong?
>
>
> Thx a lot,
> Jens