-
-
Save creationix/a0dd83511d7d75005a80 to your computer and use it in GitHub Desktop.
candor wrapping of uv_timer_t
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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