lua-users home
lua-l archive

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


Hi,

Roberto Ierusalimschy wrote:
> >     level = lua_tointeger(L, arg+2);
> >
> > level == -858993460 == 0xcccccccc
> >
> > I can't remember what that means under the Visual C++ C runtime.  I
> > think it is uninitialized memory.
> 
> May this be a bug in the macro lua_number2integer (used by
> lua_tointeger)?

lua_number2int() was an inline function in the original patch
from David Burgess (which is perfectly ok -- the #ifdef's test
for MSVC). And it used a combined _asm statement. I guess MSVC
reorders individual _asm instructions and this breaks it.

So either replace the definition at luaconf.h:439 with

   __asm { fld d; fistp i };

(don't know if this needs a newline between the two asm statements)
or replace with the original patch:

+ #pragma warning(disable: 4514)
+ __inline int lrint (double flt)
+ {     int i;
+       _asm {
+       fld flt
+       fistp i
+       };
+       return i;
+ }
+ #define lua_number2int(i,d)   ((i)=lrint((d)))

Bye,
     Mike