lua-users home
lua-l archive

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


Hi,

I have tried to compile lua with -USE_FLOAT defined in the config file (I
was using gcc-2.96 under linux mandrake 8.2). I am planning to use Lua in a
game project whose target has no hardware double precision support, guess
which one :-).
I get an error in lobject.c, line 135, because the compiler complains that a
lua_Number argument is promoted to a double by when given to a variable
number argument function, and therefore should be extracted from the va_list
as a double and not a lua_Number.
In order to correct this, I have applied the following changes :

luser_number.h:

#ifdef USE_FLOAT
#define LUA_NUMBER float
#define LUA_NUMBER_VA_ARG double // added
#define LUA_NUMBER_SCAN "%f"
#define LUA_NUMBER_FMT "%.8g"
#endif

lua.h:

#ifndef LUA_NUMBER
#define LUA_NUMBER double
#define LUA_NUMBER_VA_ARG double // added
#endif

typedef LUA_NUMBER lua_Number
typedef LUA_NUMBER_VA_ARG lua_NumberVaArg // added

lobject.c:135
setnvalue(L->top, (lua_Number) va_arg(argp, lua_NumberVaArg)); // changed


I don't know the compiler behaviour regarding integer promotion when passing
scalar values to variable number argument functions, since I don't know the
promotion policy (do they all get promoted to long or int ?). I have tried a
temporary hack by adding a USE_LONGLONG number definition in luser_number.h,
disregarding the fact that it is not supported by ansi C89, and the compiler
does not issue a warning for this particular problem. Maybe somebody who has
a 16-bits target could try and see what happens when compiling with USE_INT
and USE_LONG ?

But then, maybe this automatic float->double promotion is not a standard
language feature, and this change is not necessary for all compilers ? 

Regards,

Benoit.

> -----Original Message-----
> From: Luiz Henrique de Figueiredo [mailto:lhf@tecgraf.puc-rio.br]
> Sent: jeudi 15 août 2002 17:59
> To: Multiple recipients of list
> Subject: [ANNOUNCE] Lua 5.0 (alpha) now available
> 
> 
> Lua 5.0 (alpha) is now available for downloading at
> 	http://www.lua.org/ftp/lua-5.0-alpha.tar.gz
> 	ftp://ftp.lua.org/lua-5.0-alpha.tar.gz
> The mirror sites will be updated automatically by their own 
> robots soon.
> 
> For the record, Lua is freely available for both academic and 
> commercial
> purposes under the terms of the MIT license: 
> http://www.lua.org/license.html .
> 
> Note that this is an *alpha* release, not a work release. 
> This means that
> Lua 5.0 final is expected to be very close to it, unless 
> serious flaws are
> found. Small improvements are expected, specially in the 
> implementation, but
> no visible changes to programmers. In particular, if you're 
> interested, you can
> start porting your programs now; we don't expect to introduce 
> incompatibilities
> in Lua 5.0 final.
> 
> The tarball contains complete documentation in HTML, 
> including an updated
> reference manual and a new logo to celebrate recent sport events :-).
> Printable versions of the manual in PS and PDF are available at
> 	http://www.lua.org/ftp/refman-5.0-alpha.ps.gz
> 	http://www.lua.org/ftp/refman-5.0-alpha.pdf
> and soon at the mirror sites.
> 
> Please take some time to read the manual, as this is a major 
> new release.
> The manual still needs work: it is incomplete in parts but hopefully
> it does not says false things.
> 
> Here is a brief summary of the changes (see HISTORY for a 
> complete list):
> 
>   + lexical scoping.
>   + Lua coroutines and support for external multithreading 
> and coroutines.
>   + standard libraries now packaged in tables.
>   + tags replaced by metatables and tag methods replaced by 
> metamethods.
>   + each function can have its own global table, which can be shared.
>   + new boolean type.
>   + introduced lightweight userdata.
>   + proper tail calls.
>   + new, faster, register-based virtual machine.
>   + support to user extensions in lua.c.
>   + safe garbage-collector metamethods.
>   + new error handling protocol.
>   and much more...
> 
> Please report any problems to lua@tecgraf.puc-rio.br.
> 
> Enjoy.
> --lhf
>