lua-users home
lua-l archive

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

Hey, thanks Duncan! I don't think I could have caught that embarrassing bug on my own. Yes, removing those two redundant (I basically edited the error handling out of the example because I'm dumb) if statements worked.

Thanks again,

On Tue, Sep 27, 2011 at 7:49 PM, Duncan Cross <> wrote:
On Wed, Sep 28, 2011 at 12:10 AM, Taha Mirza <> 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:

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); *width is only assigned to if the two values on the stack are
*not* numbers, and *height is being assigned to regardless.