15 FUNCTION_TAKES_EXACTLY(1);
17 if (!IS_INTEGER(argv[0]) && !IS_FLOATING(argv[0])) {
18 return TYPE_ERROR(
int or
float,argv[0]);
21 unsigned int usecs = (IS_INTEGER(argv[0]) ? AS_INTEGER(argv[0]) :
22 (IS_FLOATING(argv[0]) ? AS_FLOATING(argv[0]) : 0)) *
27 return BOOLEAN_VAL(1);
31 FUNCTION_TAKES_NONE();
34 gettimeofday(&tv,NULL);
36 double out = (double)tv.tv_sec + (
double)tv.tv_usec / 1000000.0;
38 return FLOATING_VAL(out);
46 KRK_DOC(module,
"@brief Provides timekeeping functions.");
47 KRK_DOC(BIND_FUNC(module,sleep),
"@brief Pause execution of the current thread.\n"
49 "Uses the system @c usleep() function to sleep for @p secs seconds, which may be a @ref float or @ref int. "
50 "The available precision is platform-dependent.");
51 KRK_DOC(BIND_FUNC(module,time),
"@brief Return the elapsed seconds since the system epoch.\n\n"
52 "Returns a @ref float representation of the number of seconds since the platform's epoch date. "
53 "On POSIX platforms, this is the number of seconds since 1 January 1970. "
54 "The precision of the return value is platform-dependent.");
Struct definitions for core object types.
KrkInstance * krk_newInstance(KrkClass *_class)
Create a new instance of the given class.
KrkTable fields
Attributes table.
The most basic object type.
void krk_attachNamedObject(KrkTable *table, const char name[], KrkObj *obj)
Attach an object to an attribute table.
void krk_attachNamedValue(KrkTable *table, const char name[], KrkValue obj)
Attach a value to an attribute table.
Utilities for creating native bindings.
#define KRK_DOC(thing, text)
Attach documentation to a thing of various types.
Definitions for primitive stack references.
Core API for the bytecode virtual machine.
#define vm
Convenience macro for namespacing.
void krk_module_init_time(void)
Initialize the built-in 'time' module.