lua-users home
lua-l archive

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


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.

On Sun, Apr 18, 2010 at 21:51, Pan Shi Zhu <pan.shizhu@gmail.com> wrote:
> On Fri, Apr 16, 2010 at 11:07 AM, Henk Boom <henk@henk.ca> wrote:
>> I just fixed a subtle bug in my serialization/deserialization
>> functions for a data structure, where objects that were serialized
>> then deserialized looked identical but behaved slightly differently.
>> It was caused by something like this:
>>
>>> return 9 < 10
>> true
>>> return "9" < "10"
>> false
>>
>> Lesson learned: make sure to use tonumber() on numbers you extract
>> from strings...
>
> hmm, this works in lua.
>
> in C, the lua_tonumber() is an in-place convertion, it changes the
> value in stack and may cause unwanted behavior when you're iterating a
> table.
>



-- 
Sent from my toaster.