lua-users home
lua-l archive

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


On Mon, Apr 19, 2010 at 10:16, Henk Boom <henk@henk.ca> wrote:
> 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
>

Perhaps. I hadn't tried that.

-- 
Sent from my toaster.