summaryrefslogtreecommitdiff
path: root/src/napi-sqlite.c
diff options
context:
space:
mode:
authorEuAndreh <eu@euandre.org>2023-11-13 19:24:34 -0300
committerEuAndreh <eu@euandre.org>2023-11-13 19:24:34 -0300
commita2d8f45087d26642cd68a9d806bc85219fccf8ce (patch)
tree7b49f6c857adba01a19f973cd3e5baad2dc5dd2c /src/napi-sqlite.c
parenttests/assert-*.sh: Reuse rebuilt assets for tests (diff)
downloadpapod-a2d8f45087d26642cd68a9d806bc85219fccf8ce.tar.gz
papod-a2d8f45087d26642cd68a9d806bc85219fccf8ce.tar.xz
src/napi-sqlite.c: Add Node-API PoC
Diffstat (limited to 'src/napi-sqlite.c')
-rw-r--r--src/napi-sqlite.c61
1 files changed, 61 insertions, 0 deletions
diff --git a/src/napi-sqlite.c b/src/napi-sqlite.c
new file mode 100644
index 0000000..7c0b872
--- /dev/null
+++ b/src/napi-sqlite.c
@@ -0,0 +1,61 @@
+#include <node/node_api.h>
+
+static napi_value
+my_function(napi_env env, napi_callback_info info) {
+ napi_status status;
+ size_t argc = 1;
+ int number;
+ napi_value argv[1];
+ napi_value my_number;
+
+ status = napi_get_cb_info(env, info, &argc, argv, NULL, NULL);
+ if (status != napi_ok) {
+ napi_throw_error(env, NULL, "Failed to parse arguments FIXME i18n");
+ // FIXME: does execution somehow halt here? Or is it missing a
+ // return?
+ }
+
+ status = napi_get_value_int32(env, argv[0], &number);
+ if (status != napi_ok) {
+ napi_throw_error(env, NULL, "Invalid number was passed as argument FIXME i18n");
+ // FIXME: return?
+ }
+ number = number * 2;
+
+ status = napi_create_int32(env, number, &my_number);
+ if (status != napi_ok) {
+ napi_throw_error(env, NULL, "Unable to create return value FIXME i18n");
+ // FIXME: return?
+ }
+
+ return my_number;
+}
+
+static napi_value
+init(napi_env env, napi_value exports) {
+ napi_status status;
+ napi_value fn;
+
+ status = napi_create_function(env, NULL, 0, my_function, NULL, &fn);
+ if (status != napi_ok) {
+ napi_throw_error(env, NULL, "Unable to wrap native function FIXME i18n");
+ // FIXME: return?
+ }
+
+ status = napi_set_named_property(env, exports, "my_function", fn);
+ if (status != napi_ok) {
+ napi_throw_error(env, NULL, "Unable to populate exports FIXME i18n");
+ // FIXME: return?
+ }
+
+ return exports;
+}
+
+
+napi_value
+sqlite_napi_init(napi_env env, napi_value exports) {
+ return init(env, exports);
+}
+
+//NAPI_MODULE(NODE_GYP_MODULE_NAME, sqlite_napi_init)
+NAPI_MODULE(FIXME_CAN_THIS_BE_ANYTHING, sqlite_napi_init)