diff options
-rw-r--r-- | .gitignore | 2 | ||||
-rw-r--r-- | Makefile | 14 | ||||
-rw-r--r-- | src/napi-sqlite.c | 61 |
3 files changed, 75 insertions, 2 deletions
@@ -2,3 +2,5 @@ /doc/*.3js /src/index.js /node_modules/ +/src/napi-sqlite.lo +/src/napi-sqlite.node @@ -15,13 +15,15 @@ SRCDIR = $(PREFIX)/src/$(NAME) SHAREDIR = $(PREFIX)/share LOCALEDIR = $(SHAREDIR)/locale MANDIR = $(SHAREDIR)/man +CFLAGS.so = $(CFLAGS) -fPIC +LDFLAGS.so = $(LDFLAGS) -shared ## Where to store the installation. Empty by default. DESTDIR = .SUFFIXES: -.SUFFIXES: .in +.SUFFIXES: .in .c .lo .msg .cat .in: sed \ @@ -33,6 +35,9 @@ DESTDIR = < $< > $@ if [ -x $< ]; then chmod +x $@; fi +.c.lo: + $(CC) $(CFLAGS.so) -o $@ -c $< + manpages.en.in = \ @@ -70,6 +75,8 @@ derived-assets = \ node_modules/dir.sentinel \ node_modules/ \ node_modules/$(NAME) \ + src/napi-sqlite.lo \ + src/napi-sqlite.node \ side-assets = \ ircd.sock \ @@ -82,7 +89,10 @@ side-assets = \ all: $(derived-assets) -$(manpages): Makefile +$(manpages) src/napi-sqlite.lo: Makefile + +src/napi-sqlite.node: src/napi-sqlite.lo + $(CC) $(LDFLAGS.so) -o $@ src/napi-sqlite.lo src/index.js: ln -fs api.js $@ 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) |