lua-users home
lua-l archive

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


On 3/13/15, Roberto Ierusalimschy <roberto@inf.puc-rio.br> wrote:
>> That does look interesting, although we'd have to check whether it
>> is possible for us to switch to LuaJIT. The last time I looked at it
>> that was not possible for lack of 64bit integer support (unfortunately
>> Lua's default numeric type "double" is not at all appropriate
>> to our applications, and our Lua 5.1 is configured to use int64_t
>> instead, something that Lua is well designed to handle). However it
>> seems that in the meantime LuaJIT has gained support for some boxed
>> 64bit integers, which might be good enough if well integrated...
>
> (Out of topic) Can you give a brief explanation about why you need
> 64bit integer support? (I am writing something about the introduction
> of integers in Lua 5.3, and it would be good to have some more concrete
> examples of why people need 64bit integers.)
>
> -- Roberto
>


For me, it was because APIs used 64-bit integers and I was binding Lua
directly to these APIs. In OS X/Cocoa, the move to native 64-bit began
seriously in 2007 with 10.5. (For context: Remember that Apple had
just migrated from PowerPC to Intel. I believe there was only one
32-bit only Intel Mac sold, the very first cheapest Mac Mini which was
discontinued in 2006. So there was never a large legacy base holding
native 64-bit back from being adopted. And the major improvements to
Objective-C 2.0 wanted to make breaking ABI changes, so Apple made
those available to 64-bit only since there was no 64-bit Cocoa prior
to 10.5 so there was nothing to break. Hence developers moved to
64-bit quickly.)

The basic integer everything uses in Cocoa is NSInteger which is
#define'd to long. So on 64-bit architectures, it is a full blown
64-bit quantity.

Here is NSMutableArray's API to remove an element from the array as an example:
- (void)removeObjectAtIndex:(NSUInteger)index;
Imagine hundreds or thousands of Cocoa APIs that use NSInteger and
NSUInteger just like this one.

Every API in Cocoa that uses an integer needs a 64-bit integer under
64-bit architectures.  Binding these to Lua was problematic with only
a double available.

You might get away with it if you don't need the higher bits, but some
constants throw a monkey wrench into this. For example, I think some
enums define the last value in the enum as NSIntegerMax or
NSIntegerMin. (I think to denote an error, out-of-bounds, or
undefined/null value.) So if you need to compare your value to those
constants, your comparison gives the incorrect results.


-Eric
-- 
Beginning iPhone Games Development
http://playcontrol.net/iphonegamebook/