Merge branch 'master' into array_fix
This commit is contained in:
commit
1a4dc82931
1964 changed files with 57298 additions and 30865 deletions
|
|
@ -4,6 +4,7 @@ constant
|
|||
enum
|
||||
exception
|
||||
functor
|
||||
native
|
||||
nspace
|
||||
operator
|
||||
overload
|
||||
|
|
|
|||
|
|
@ -30,5 +30,5 @@ f.enum_test(example.Foo.LUDICROUS);
|
|||
// enum value BLUE of enum color is accessed as property of cconst
|
||||
console.log("example.BLUE= " + example.BLUE);
|
||||
|
||||
// enum value LUDICROUS of enum Foo::speed is accessed as as property of cconst
|
||||
// enum value LUDICROUS of enum Foo::speed is accessed as property of cconst
|
||||
console.log("example.speed.LUDICROUS= " + example.Foo.LUDICROUS);
|
||||
|
|
|
|||
|
|
@ -16,30 +16,26 @@ public:
|
|||
char msg[256];
|
||||
};
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#pragma warning(disable: 4290) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow)
|
||||
#endif
|
||||
|
||||
class Test {
|
||||
public:
|
||||
int simple() throw(int) {
|
||||
int simple() {
|
||||
throw(37);
|
||||
return 1;
|
||||
}
|
||||
int message() throw(const char *) {
|
||||
int message() {
|
||||
throw("I died.");
|
||||
return 1;
|
||||
}
|
||||
int hosed() throw(Exc) {
|
||||
int hosed() {
|
||||
throw(Exc(42,"Hosed"));
|
||||
return 1;
|
||||
}
|
||||
int unknown() throw(A*) {
|
||||
int unknown() {
|
||||
static A a;
|
||||
throw &a;
|
||||
return 1;
|
||||
}
|
||||
int multi(int x) throw(int, const char *, Exc) {
|
||||
int multi(int x) {
|
||||
if (x == 1) throw(37);
|
||||
if (x == 2) throw("Bleah!");
|
||||
if (x == 3) throw(Exc(42,"No-go-diggy-die"));
|
||||
|
|
@ -47,7 +43,3 @@ public:
|
|||
}
|
||||
};
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#pragma warning(default: 4290) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow)
|
||||
#endif
|
||||
|
||||
|
|
|
|||
|
|
@ -7,6 +7,12 @@
|
|||
|
||||
%include "std_string.i"
|
||||
|
||||
%catches(int) Test::simple();
|
||||
%catches(const char *) Test::message();
|
||||
%catches(Exc) Test::hosed();
|
||||
%catches(A*) Test::unknown();
|
||||
%catches(int, const char *, Exc) Test::multi(int x);
|
||||
|
||||
/* Let's just grab the original header file here */
|
||||
%include "example.h"
|
||||
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ try{
|
|||
if(error == -1) {
|
||||
console.log("t.unknown() didn't throw");
|
||||
} else {
|
||||
console.log("successfully catched throw in Test::unknown().");
|
||||
console.log("successfully caught throw in Test::unknown().");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -22,7 +22,7 @@ catch(error){
|
|||
if(error == -1) {
|
||||
console.log("t.simple() did not throw");
|
||||
} else {
|
||||
console.log("successfully catched throw in Test::simple().");
|
||||
console.log("successfully caught throw in Test::simple().");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -33,7 +33,7 @@ try{
|
|||
if(error == -1) {
|
||||
console.log("t.message() did not throw");
|
||||
} else {
|
||||
console.log("successfully catched throw in Test::message().");
|
||||
console.log("successfully caught throw in Test::message().");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -45,7 +45,7 @@ catch(error){
|
|||
if(error == -1) {
|
||||
console.log("t.hosed() did not throw");
|
||||
} else {
|
||||
console.log("successfully catched throw in Test::hosed().");
|
||||
console.log("successfully caught throw in Test::hosed().");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -58,7 +58,7 @@ for (var i=1; i<4; i++) {
|
|||
if(error == -1) {
|
||||
console.log("t.multi(" + i + ") did not throw");
|
||||
} else {
|
||||
console.log("successfully catched throw in Test::multi().");
|
||||
console.log("successfully caught throw in Test::multi().");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
3
Examples/javascript/native/Makefile
Normal file
3
Examples/javascript/native/Makefile
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
SRCS =
|
||||
|
||||
include $(SRCDIR)../example.mk
|
||||
9
Examples/javascript/native/binding.gyp.in
Normal file
9
Examples/javascript/native/binding.gyp.in
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
{
|
||||
"targets": [
|
||||
{
|
||||
"target_name": "example",
|
||||
"sources": [ "example_wrap.cxx" ],
|
||||
"include_dirs": ["$srcdir"]
|
||||
}
|
||||
]
|
||||
}
|
||||
47
Examples/javascript/native/example.i
Normal file
47
Examples/javascript/native/example.i
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
/* File : example.i */
|
||||
%module example
|
||||
|
||||
// placeholder() used to help SWIG generate "SWIG_From_int" call
|
||||
%{
|
||||
int placeholder();
|
||||
%}
|
||||
int placeholder() { return 0; }
|
||||
|
||||
// actual demo code
|
||||
%wrapper
|
||||
%{
|
||||
#ifdef SWIG_V8_VERSION /* Engine: Node || V8 */
|
||||
|
||||
static SwigV8ReturnValue JavaScript_do_work(const SwigV8Arguments &args) {
|
||||
SWIGV8_HANDLESCOPE();
|
||||
const int MY_MAGIC_NUMBER = 5;
|
||||
SWIGV8_VALUE jsresult =
|
||||
SWIG_From_int(static_cast< int >(MY_MAGIC_NUMBER));
|
||||
if (args.Length() != 0)
|
||||
SWIG_exception_fail(SWIG_ERROR, "Illegal number of arguments.");
|
||||
SWIGV8_RETURN(jsresult);
|
||||
fail:
|
||||
SWIGV8_RETURN(SWIGV8_UNDEFINED());
|
||||
}
|
||||
|
||||
#else /* Engine: JavaScriptCore */
|
||||
|
||||
static JSValueRef JavaScript_do_work(JSContextRef context,
|
||||
JSObjectRef function, JSObjectRef thisObject, size_t argc,
|
||||
const JSValueRef argv[], JSValueRef* exception) {
|
||||
const int MY_MAGIC_NUMBER = 5;
|
||||
JSValueRef jsresult =
|
||||
SWIG_From_int SWIG_JSC_FROM_CALL_ARGS(
|
||||
static_cast< int >(MY_MAGIC_NUMBER));
|
||||
if (argc != 0)
|
||||
SWIG_exception_fail(SWIG_ERROR, "Illegal number of arguments.");
|
||||
return jsresult;
|
||||
fail:
|
||||
return JSValueMakeUndefined(context);
|
||||
}
|
||||
|
||||
#endif
|
||||
%}
|
||||
|
||||
|
||||
%native(magicNumber) void JavaScript_do_work();
|
||||
1
Examples/javascript/native/example.js
Normal file
1
Examples/javascript/native/example.js
Normal file
|
|
@ -0,0 +1 @@
|
|||
module.exports = require("build/Release/example");
|
||||
31
Examples/javascript/native/index.html
Normal file
31
Examples/javascript/native/index.html
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
<html>
|
||||
<head>
|
||||
<title>SWIG:Examples:javascript:native</title>
|
||||
</head>
|
||||
|
||||
<body bgcolor="#ffffff">
|
||||
|
||||
|
||||
<tt>SWIG/Examples/javascript/native/</tt>
|
||||
<hr>
|
||||
|
||||
<H2>Manually wrapped callback function in JavaScript</H2>
|
||||
|
||||
<p>
|
||||
This example demonstrates how to manually add callback feature support to a SWIG module.
|
||||
</p>
|
||||
|
||||
<ul>
|
||||
<li><a href="example.i">example.i</a>. Interface file containing the API function and async behind-the-scenes functions.
|
||||
<li><a href="runme.java">runme.js</a>. Sample JavaScript program showing the API function being called with a callback function parameter.
|
||||
</ul>
|
||||
|
||||
<h2>Notes</h2>
|
||||
|
||||
The V8 code queues the callback request for processing using the UV interface. An async function callback is invoked when the system is ready to process the next request. When the async function finishes, a completion function callback is invoked to finalize the request. Here the callback function parameter is invoked.
|
||||
<br/><br/>
|
||||
UV request queueing is only necessary for operations that would take a really long or otherwise unpredictable amount of time (async operations). A callback parameter could also be invoked immediately within the API function.
|
||||
|
||||
<hr>
|
||||
</body>
|
||||
</html>
|
||||
3
Examples/javascript/native/runme.js
Normal file
3
Examples/javascript/native/runme.js
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
var example = require("example");
|
||||
|
||||
console.log("My magic number is: ", example.magicNumber());
|
||||
|
|
@ -44,7 +44,7 @@ example.print_vars();
|
|||
|
||||
console.log("\nNow I'm going to try and modify some read only variables");
|
||||
|
||||
console.log("Tring to set 'path'");
|
||||
console.log("Trying to set 'path'");
|
||||
try{
|
||||
example.path = "Whoa!";
|
||||
console.log("Hey, what's going on?!?! This shouldn't work");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue