Skip to content

Instantly share code, notes, and snippets.

@creationix
Created March 8, 2012 16:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save creationix/a0dd83511d7d75005a80 to your computer and use it in GitHub Desktop.
Save creationix/a0dd83511d7d75005a80 to your computer and use it in GitHub Desktop.
candor wrapping of uv_timer_t
static Value* NewTimer(uint32_t argc, Arguments& argv) {
HandleScope scope;
// Allocate a timer first locally, then copy to heap
uv_timer_t t;
String* cdata = String::New(reinterpret_cast<char*>(&t), sizeof(t));
// Get a pointer to the heap version and initialize it
uv_timer_t* handle = (uv_timer_t*)cdata->Value();
uv_timer_init(uv_default_loop(), handle);
// Create an object with cdata and type properties and return it.
Handle<Object> timer(Object::New());
timer->Set(String::New("cdata", 5), cdata);
timer->Set(String::New("type", 4), String::New("timer", 5));
return *timer;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment