This repository has been archived by the owner on Oct 15, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 340
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge 5f22375 as of 2017-09-09. This is an automatically created merge. For any problems please contact @kunalspathak.
- Loading branch information
Showing
10 changed files
with
290 additions
and
16 deletions.
There are no files selected for viewing
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#include <node.h> | ||
#include <v8.h> | ||
|
||
#ifndef _WIN32 | ||
|
||
#include <dlfcn.h> | ||
|
||
extern "C" const char* dlopen_pong(void) { | ||
return "pong"; | ||
} | ||
|
||
namespace { | ||
|
||
using v8::FunctionCallbackInfo; | ||
using v8::Isolate; | ||
using v8::Local; | ||
using v8::Object; | ||
using v8::String; | ||
using v8::Value; | ||
|
||
typedef const char* (*ping)(void); | ||
|
||
static ping ping_func; | ||
|
||
void LoadLibrary(const FunctionCallbackInfo<Value>& args) { | ||
const String::Utf8Value filename(args[0]); | ||
void* handle = dlopen(*filename, RTLD_LAZY); | ||
assert(handle != nullptr); | ||
ping_func = reinterpret_cast<ping>(dlsym(handle, "dlopen_ping")); | ||
assert(ping_func != nullptr); | ||
} | ||
|
||
void Ping(const FunctionCallbackInfo<Value>& args) { | ||
Isolate* isolate = args.GetIsolate(); | ||
assert(ping_func != nullptr); | ||
args.GetReturnValue().Set(String::NewFromUtf8(isolate, ping_func())); | ||
} | ||
|
||
void init(Local<Object> exports) { | ||
NODE_SET_METHOD(exports, "load", LoadLibrary); | ||
NODE_SET_METHOD(exports, "ping", Ping); | ||
} | ||
|
||
NODE_MODULE(binding, init) | ||
|
||
} // anonymous namespace | ||
|
||
#endif // _WIN32 |
Oops, something went wrong.