Skip to content

Commit 0c0af59

Browse files
committed
node.js binding added
1 parent 0dd5577 commit 0c0af59

File tree

3 files changed

+34
-1
lines changed

3 files changed

+34
-1
lines changed

CMakeLists.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,21 @@ if(SWIG_FOUND)
333333
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/infoLoggerForGo.go DESTINATION ${CMAKE_INSTALL_LIBDIR})
334334
endif()
335335

336+
#library for Javascript / node.js
337+
find_program(NODE_EXECUTABLE node)
338+
get_filename_component(NODE_DIR ${NODE_EXECUTABLE} DIRECTORY)
339+
find_path(NODEJS_INCLUDE_DIRS NAMES node.h PATHS ${Nodejs_ROOT} ${Nodejs_ROOT}/include ${NODE_DIR}/../include/node)
340+
if (NODEJS_INCLUDE_DIRS)
341+
message("Bindings for node.js will be generated")
342+
message("Using NODEJS_INCLUDE_DIRS=${NODEJS_INCLUDE_DIRS}")
343+
set(CMAKE_SWIG_FLAGS -module infoLoggerForNodejs -v8)
344+
swig_add_library(infoLoggerForNodejs LANGUAGE javascript SOURCES src/infoLogger.i ${INFOLOGGER_LIB_OBJECTS})
345+
target_include_directories(${SWIG_MODULE_infoLoggerForNodejs_REAL_NAME} PRIVATE ${INFOLOGGER_INCLUDE_DIRS} ${NODEJS_INCLUDE_DIRS})
346+
target_compile_definitions(${SWIG_MODULE_infoLoggerForNodejs_REAL_NAME} PRIVATE -DBUILDING_NODE_EXTENSION)
347+
set_target_properties(${SWIG_MODULE_infoLoggerForNodejs_REAL_NAME} PROPERTIES OUTPUT_NAME infoLogger SUFFIX ".node")
348+
install(TARGETS ${SWIG_MODULE_infoLoggerForNodejs_REAL_NAME} DESTINATION ${CMAKE_INSTALL_LIBDIR})
349+
endif()
350+
336351
endif()
337352

338353

doc/README.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ The InfoLogger library allows to inject messages directly from programs, as show
216216
217217
Usually, one will only take care of defining the per-message messageOptions struct and a context with appropriate Facility field set, all other being set automatically.
218218
219-
* InfoLogger library is also available for: Tcl, Python, Go.
219+
* InfoLogger library is also available for: Tcl, Python, Go, Node.js.
220220
It allows to log message from scripting languages. A simplified subset of the InfoLogger C++ API is made available through SWIG-generated modules.
221221
Example usage is shown below. Files listed there are available from the infoLogger library installation directory.
222222
@@ -253,6 +253,17 @@ The InfoLogger library allows to inject messages directly from programs, as show
253253
logHandle.LogError("Something went wrong")
254254
}
255255
```
256+
* Node.js
257+
** Library files: infoLogger.node
258+
** Code example: (interactive interpreter from the command line)
259+
```
260+
node
261+
var infoLoggerModule=require("infoLogger");
262+
var logHandle=new infoLoggerModule.InfoLogger();
263+
logHandle.logInfo("This is a test");
264+
logHandle.logError("Something went wrong");
265+
```
266+
256267
257268
258269
## Configuration

src/infoLogger.i

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@
1313
%}
1414

1515

16+
#ifdef SWIG_JAVASCRIPT_V8
17+
%inline %{
18+
#include <node.h>
19+
%}
20+
#endif
21+
22+
1623
%include <exception.i>
1724
%exception {
1825
try {

0 commit comments

Comments
 (0)