[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: using 'uint64_t' with Alien
- From: Sam Roberts <vieuxtech@...>
- Date: Wed, 8 Jul 2009 13:02:41 -0700
On Wed, Jul 8, 2009 at 12:47 PM, Phoenix Sol<email@example.com> wrote:
> Aha; Thanks, Fabio.
> So then I need to wrap those C functions with my own, correct?
> ( I'm still pretty ignorant of C, unfortunately... I wonder if I can do an
> implicit conversion, and 'shoe-horn' longs in there? I'm about to try it,
> but do please reply if you have an answer. )
> The relevant functions are from 'tcrdb' in tokyotyrant; three which take
> 'uint64_t' timestamps in microseconds, and two which return them.
> Is there another way to do this manipulation? Or am I just being silly? (I'm
> pretty sure I can write a little C.)
I'm not familiar with alien, but I think you'd have to write C code to
create a uint64 userdata.
Google the list for lots of discussion.
But, do people need to do arithmetic on the timestamps? I.e., do they
really need to pass them around as numbers? Add them? Divide them?
Pass to math.sin()? Probably not. It's convenient to keep timestamps
as a numeric type in C, but not in Lua.
I'd suggest using a string to pass them around as the decimal
representation of usecs, that makes them easy to print, and easy to
set. You could even provide library functions:
.breakdown(a) -> return seconds and microseconds (easy to do by
truncating bottom 6 characters, and then returning tonumber() of the
seconds part and microseconds part?)
Converting to/from uint64 and a string is easy in C.