lua-users home
lua-l archive

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


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