lua-users home
lua-l archive

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


Hi,

I am new to Lua, and although I have been reviewing previous mails trying to find the answer to this and studying the code, I could not find anything relevant.

I am trying to use Lua to extend a legacy 16-bit MSDOS application compiled with Borland C 3.1. I cannot change that environment (i.e. I cannot move to protected mode and DJGPP). I downloaded version 5.1 and made a new entry in the makefile with the following settings:

CC=bcc CFLAGS="-ml -DLUA_ANSI" LIBS= RANLIB=echo MYLDFLAGS=-ml

and after changing a few details, like ".o" for ".obj" and ".a" for ".lib", everything compiles and links properly. However, there is a strange bug both in lua.exe and in luac.exe. The bug seems to be related to the logical operator OR, when the left argument is nil or false and the right argument is a number constant (not a variable with a numeric value). For example,

> print(nil or 0)
2.2968702947708e-180

> print(false or 1234.5678)
2.2968702947708e-180

This should have printed the second argument. Other combinations work correctly:

> x=0
> print(nil or x)
0

> print(nil or "hello")
hello

> print(false or true)
true

> print(22 or 33)
22

> print(10 or false)
10

I tried different memory models like huge, increasing the stack size, a different compiler (Digital Mars), all with same result. Windows and Linux versions work OK with any compiler, so this looks like a 16/32 bit thing. Interestingly, the 16-bit version works properly if you compile with the following flag:

-Ddouble=float (this replaces 64-bit doubles with 32-bit floats). 

So I guess that either the size or the alignment of something is wrong somewhere, but I cannot find it.

Any clues?

Thanks a lot,
Hugo Etchegoyen