lua-users home
lua-l archive

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


> > Does this work straight out of the box? I really like light
> > solutions, especially when operating on negative time :-)
> >
> >   Enrico
> It's always worked.  At least with Lua 5.
> 
> But this is exactly why I did the Number patch, to avoid such  
> hacks.... !    ;D

In fact, looking back at the source code for that ARM project it seems I
used Asko's integer optimisation patch and then used an explicit fixed
point user data module.

This did mean that initialising a fixed point type had to be done with a
string rather than a number but apart from that it worked well. An added
bonus was being able to set the number of precision bits at
initialisation rather than having a set value for everything.

The only problems that I recall were that I didn't implement code to
allow lua integers to interact with the fixed point types. So this sort
of thing was not possible:

local f = fixed.new("12.234")
local r = f * 10 -- would have to be written as f * fixed.new("10")

I could easily have written the metamethods to handle that case but the
reverse (10 * f) would always have been problematic I think.

To answer your question, more concisely: Yes, it worked very well for my
needs.

- DC