Re: Problem reading Lua variables from C++
[
Date Prev][
Date Next][
Thread Prev][
Thread Next]
[
Date Index]
[
Thread Index]
- Subject: Re: Problem reading Lua variables from C++
- From: Duncan Cross <duncan.cross@...>
- Date: 2011年9月28日 00:49:15 +0100
On Wed, Sep 28, 2011 at 12:10 AM, Taha Mirza <bowserevilking@gmail.com> wrote:
> Hi, this is my first post in a mailing list ever, so forgive me if i screw
> up a little.
>
> Now, I've explained the problem in a forum post, so rather than quoting the
> whole thing here, I'll just link you to it:
> http://forum.luahub.com/index.php?topic=3253.0
The problem seems to be here:
| if (!lua_isnumber(L, -2))
| if (!lua_isnumber(L, -1))
| *width = (int)lua_tonumber(L, -2);
| *height = (int)lua_tonumber(L, -1);
It looks like you may have assumed that those "if" statements would
just be ignored, but in fact they are being interpreted like this:
| if (!lua_isnumber(L, -2)) {
| if (!lua_isnumber(L, -1)) {
| *width = (int)lua_tonumber(L, -2);
| }
| }
| *height = (int)lua_tonumber(L, -1);
...so *width is only assigned to if the two values on the stack are
*not* numbers, and *height is being assigned to regardless.
-Duncan