lua-users home
lua-l archive

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



Yes, there were two separate problems.
And I think that the solution must require only modifying luaconf.h and
not patching lstrlib.c by hand.

The problem that is in my setup
string.format parameter %x must be mapped to C parameter %I64x.
This mapping is done in function scanformat.
And it does not know that I changed lua_Number to be bigger than int,
so it blindly maps lua %x to c %x.

The problem is that I think that string.format("%x") means
"Show me lua number with hex digits" but it actually means
"Show an C int with hex digits". I think that the former interpretation is
more natural to the programmer (at least if she wants 64 bit lua numbers
then she expects to be able to format them).

There are two solutions:
1) keep the current meaning and allow the lua code to use full range
of C modifiers, i.e. lua code string.format("%llx") is valid. But this will
break independance of the lua code from underlying C lib.
2) change semantics of lua modifier %x to mean
"Show lua number with hex digits".

I really prefer option 2) but I dont know whether this can be made for 5.1 stable. Anyway, I'll be glad of some help how to deal with this issue in a portable manner, so other people that uses 64 bit numbers can easily apply the sollution for themselves. As I use Lua as in-house solution I'm free to patch it as I wish so I hacked
an ugly temporary code that is firmly tied to VS2003 and i'm happy with it.

Best regards,
Todor

The first is
that str_format believes that lua_Number is double. So we actually need
the cast to double in the cases eEfgG.

The second is the integer conversions. In that case, str_format does not
typecast lua_Numbers impropertly. Cases ouxXd demand an int argument,
and this is what Lua provides. The problem here is that Lua provides
only these formats; it has nothing to do with lua_Number being double or
not. (Actually an integer as a a double has more than 32 bits, so it
will be truncated too.)

Formats %I64x or %I64d are not standard, but neither are %llx or %lld
in C89 (ll is standard in C99 however). Probably we could add some
configuration to these formats (a prefix, like "I64" or "ll", and
an integer type, like long long).

-- Roberto