[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Limitations of standard C, formal interfaces, and other musings. Was: ms-level timings
- From: Rici Lake <lua@...>
- Date: Wed, 4 Aug 2004 13:23:03 -0500
This sort of question comes up a lot.
On 4-Aug-04, at 12:53 PM, Asko Kauppi wrote:
Is there currently a nice, standard way of doing sub-second timings
with Lua?
I think not. 'os.clock()' gives CPU time, not real one. 'os.time()'
gives 1sec granularity, which is ..well.. often not so good.
Core Lua provides no more than can be done with the standard C
libraries. One reference I use for standard C (there might be better
ones) is here: http://www-ccs.ucsd.edu/c/index.html
If you can't figure out how to implement a feature using no more than
is provided by the standard C libraries, then chances are pretty good
that Lua won't provide it out of the box. If you can, and Lua doesn't
provide it, I'm sure that contributions would be welcome. :)
The classic example is directory listings. Close examination of the
standard C libraries will reveal that the complete absence of functions
to deal with directories. The only requirement on filenames is that
they can be represented by a null-terminated string. Indeed, C can be
implemented on a platform which has no concept of directories
whatsoever.
Notwithstanding the above, I personally think it would be cool to have
a definition of what the interfaces for an "extended library" would be,
if the facilities existed on the platform in question. Then, for
example, we (collectively) could create io. and os. extended libraries
for our various platforms according to that standard.
I know this idea has been discussed many times before and there are
various conflicting ideas on how to do this, so perhaps it is all a
rat's nest which shouldn't be opened again.
Incidentally, I think this points to an important aspect of the debate
about packaging. The definition of a package *interface* and the
*implementation* of that interface are two different things. There
might be various implementations of an interface, and not just because
of platform differences. A particular interface description could
include optional prototypes -- "this is what the API would look like if
it were available" -- and individual consumers of an implementation of
that interface should be able to figure out if the implementation does
or does not implement these optional features (in many cases, the test
"if module.optionalFunction then ... " would be sufficient; if not, the
interface needs to explain also how to do the check.)
Perhaps this is all too formal for a light-weight language like Lua.
But we can also take advantage of the learning about what didn't work
from other scripting languages.
Rici