[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Make sure numbers are numbers
- From: Henk Boom <henk@...>
- Date: Mon, 19 Apr 2010 12:16:25 -0400
On 19 April 2010 00:06, HyperHacker <hyperhacker@gmail.com> wrote:
> The solution to that is to copy it:
> lua_pushvalue(L, someindex);
> n = lua_tonumber(L, -1);
> lua_pop(L, 1);
> You can define C preprocessor macros for this, but they get a little
> hairy for the fact that macros can't return a value. Better to use a
> function.
Aside from the fact that lua_tonumber doesn't actually change the
stack, and that it IS actually better to use a function, why couldn't
the comma operator be used for this?
http://en.wikipedia.org/wiki/Comma_operator
Something like this (let me know if I'm wrong):
lua_Number COPY_TONUMBER__n;
#define COPY_TONUMBER(L, index) ( \
lua_pushvalue(L, index), \
COPY_TONUMBER__n = lua_tonumber(), \
lua_pop(L, 1), \
COPY_TONUMBER__n \
)
..
lua_Number n = COPY_TONUMBER(L, 1);
..
henk