-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpointers.cpp
More file actions
58 lines (47 loc) · 1.2 KB
/
pointers.cpp
File metadata and controls
58 lines (47 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include "pointers.hpp"
#include "util.hpp"
#include <napi_bind.hpp>
using napi_bind::ok;
using napi_bind::set_function;
struct test_struct
{
uint16_t payload;
};
void *create_null_ptr()
{
return nullptr;
}
test_struct *create_struct_ptr()
{
return new test_struct();
}
void *create_void_ptr()
{
return create_struct_ptr();
}
void delete_struct_ptr(test_struct *ptr)
{
delete ptr;
}
void delete_void_ptr(void *ptr)
{
delete static_cast<test_struct *>(ptr);
}
uintptr_t get_ptr_address(void *ptr)
{
return reinterpret_cast<uintptr_t>(ptr);
}
napi_value create_pointers(napi_env env)
{
napi_value value;
ok(env, napi_create_object(env, &value));
set_function(env, value, "create_null_ptr", create_null_ptr);
set_function(env, value, "create_struct_ptr", create_struct_ptr);
set_function(env, value, "create_void_ptr", create_void_ptr);
set_function(env, value, "delete_struct_ptr", delete_struct_ptr);
set_function(env, value, "delete_void_ptr", delete_void_ptr);
set_function(env, value, "get_ptr_address", get_ptr_address);
set_function(env, value, "identity_struct_ptr", identity<test_struct *>);
set_function(env, value, "identity_void_ptr", identity<void *>);
return value;
}