Skip to content

Commit

Permalink
Adding the waku_addon.c code that allows the use of NimWaku in NodeJs
Browse files Browse the repository at this point in the history
Notice that it is not yet fully operative because there are issues
between the NodeJs GC and the Nim's GC, i.e. memory allocated by the
Nim's GC is freed by the NodeJs GC producing a crash.
  • Loading branch information
Ivansete-status committed May 22, 2023
1 parent 59a5c3c commit 80a9fa9
Show file tree
Hide file tree
Showing 6 changed files with 1,218 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,4 @@ nimbus-build-system.paths

# Ignore autogenerated C-bingings compilation files
/examples/cbindings/libwaku.h
/examples/nodejs/build/
9 changes: 9 additions & 0 deletions examples/nodejs/binding.gyp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"targets": [
{
"target_name": "waku",
"sources": [ "waku_addon.c" ],
"libraries": [ "-lwaku", "-L../../../build/" ]
}
]
}
45 changes: 45 additions & 0 deletions examples/nodejs/libwaku.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/* Generated by Nim Compiler v1.6.11 */
#ifndef __libwaku__
#define __libwaku__
#define NIM_INTBITS 64

#include "nimbase.h"
#undef LANGUAGE_C
#undef MIPSEB
#undef MIPSEL
#undef PPC
#undef R3000
#undef R4000
#undef i386
#undef linux
#undef mips
#undef near
#undef far
#undef powerpc
#undef unix
typedef struct ConfigNode ConfigNode;
typedef struct NimStringDesc NimStringDesc;
typedef struct TGenericSeq TGenericSeq;
struct TGenericSeq {NI len;
NI reserved;
};
struct NimStringDesc { TGenericSeq Sup;NIM_CHAR data[SEQ_DECL_SIZE];
};
typedef N_CDECL_PTR(void, tyProc__5cp59bim9aJ4WupX5aVaD1Sg) (NCSTRING signal_0);
N_LIB_PRIVATE N_NOCONV(void, signalHandler)(int sign);
N_LIB_PRIVATE N_NIMCALL(NI, getRefcount)(void* p);
N_LIB_IMPORT N_CDECL(NIM_BOOL, waku_new)(ConfigNode* config, NimStringDesc** jsonResp);
N_LIB_IMPORT N_CDECL(NCSTRING, waku_version)(void);
N_LIB_IMPORT N_CDECL(void, waku_set_event_callback)(tyProc__5cp59bim9aJ4WupX5aVaD1Sg callback);
N_LIB_IMPORT N_CDECL(void, waku_content_topic)(NCSTRING appName, NU appVersion, NCSTRING contentTopicName, NCSTRING encoding, NimStringDesc** outContentTopic);
N_LIB_IMPORT N_CDECL(void, waku_pubsub_topic)(NCSTRING topicName, NimStringDesc** outPubsubTopic);
N_LIB_IMPORT N_CDECL(void, waku_default_pubsub_topic)(NimStringDesc** defPubsubTopic);
N_LIB_IMPORT N_CDECL(NIM_BOOL, waku_relay_publish)(NCSTRING pubSubTopic, NCSTRING jsonWakuMessage, NI timeoutMs, NimStringDesc** jsonResp);
N_LIB_IMPORT N_CDECL(void, waku_start)(void);
N_LIB_IMPORT N_CDECL(void, waku_stop)(void);
N_LIB_IMPORT N_CDECL(NIM_BOOL, waku_relay_subscribe)(NCSTRING pubSubTopic, NimStringDesc** jsonResp);
N_LIB_IMPORT N_CDECL(NIM_BOOL, waku_relay_unsubscribe)(NCSTRING pubSubTopic, NimStringDesc** jsonResp);
N_LIB_IMPORT N_CDECL(NIM_BOOL, waku_connect)(NCSTRING peerMultiAddr, NU timeoutMs, NimStringDesc** jsonResp);
N_LIB_IMPORT N_CDECL(void, waku_poll)(void);
N_LIB_IMPORT N_CDECL(void, NimMain)(void);
#endif /* __libwaku__ */
Loading

0 comments on commit 80a9fa9

Please sign in to comment.