Javascript examples.

This commit is contained in:
Oliver Buchtala 2013-09-27 02:46:11 +02:00
commit 48af60d829
76 changed files with 1685 additions and 0 deletions

View file

@ -0,0 +1,21 @@
TOP = ../..
SWIG = $(TOP)/../preinst-swig
CXXSRCS = example.cxx
JS_SCRIPT = runme.js
TARGET = example
INTERFACE = example.i
wrapper::
$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' javascript_wrapper_cpp
build:: wrapper
$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' javascript_build
clean::
$(MAKE) -f $(TOP)/Makefile javascript_clean
check:: build
$(MAKE) -f $(TOP)/Makefile JSCXXSRCS='$(JSCXXSRCS)' TARGET='$(TARGET)' \
TOP='$(TOP)' JS_SCRIPT='$(JS_SCRIPT)' javascript_run

View file

@ -0,0 +1,8 @@
{
"targets": [
{
"target_name": "example",
"sources": [ "example_wrap.cxx" ]
}
]
}

View file

@ -0,0 +1,28 @@
#include <iostream>
void f() {
std::cout << "Called f()." << std::endl;
}
void f(int val) {
std::cout << "Called f(int)." << std::endl;
}
void f(int val1, int val2) {
std::cout << "Called f(int, int)." << std::endl;
}
void f(const char* s) {
std::cout << "Called f(const char*)." << std::endl;
}
void f(bool val) {
std::cout << "Called f(bool)." << std::endl;
}
void f(long val) {
std::cout << "Called f(long)." << std::endl;
}
void f(double val) {
std::cout << "Called f(double)." << std::endl;
}

View file

@ -0,0 +1,16 @@
/* File : example.i */
%module example
%{
#include "example.h"
%}
/*
Note: overloading is implemented in a sloppy way currently
i.e., only the number of arguments is taken into conideration
for dispatching.
To solve the problem one has to rename such conflicting methods.
*/
%rename(f_double) f(double val);
%include "example.h"

View file

@ -0,0 +1,9 @@
var example = require("./build/Release/example");
example.f();
example.f(1);
example.f(1, 2);
example.f("bla");
example.f(false);
example.f(11111111111);
example.f_double(1.0);