HomeForumSourceResearchGuide
Sign in to contribute to source. how it works
Native library TimerLib by barry
expand copy to clipboardexpand
//Written by Barry Porter, 2016

#include "dana_lib_defs.h"

#include 
#include 
#include 

static CoreAPI *api;

#ifdef WINDOWS
#include 
#endif

#ifdef LINUX
#include 
#include 
#include 
#endif

#include "nli_util.h"
#include "vmi_util.h"

INSTRUCTION_DEF op_timer_sleep(FrameData* cframe)
	{
	size_t ms = api -> getParamInt(cframe, 0);
	
	#ifdef WINDOWS
	Sleep(ms);
	#endif
	#ifdef LINUX
	struct timespec ts;
	ts.tv_sec = ms / 1000;
	ts.tv_nsec = (ms - (ts.tv_sec * 1000)) * 1000000;
	nanosleep(&ts, NULL);
	#endif
	
	return RETURN_OK;
	}

Interface* load(CoreAPI *capi)
	{
	api = capi;
	
	setInterfaceFunction("sleep", op_timer_sleep);
	
	return getPublicInterface();
	}

void unload()
	{
	
	}
Revision history
To propose a new revision to this entity, use dana source put -uls your/new/version.c -n TimerLib -gni time.Timer -apiv 17 -m "reason for update" -u yourUsername
Version 1 (this version) by barry
Notes for this version: Standard Library Initialisation