Add swig configuration files for v8.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/oliverb-javascript-v8@13765 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
050219d998
commit
35e6b73d2a
20 changed files with 630 additions and 193 deletions
|
|
@ -6,7 +6,7 @@
|
|||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
%include <javscriptcomplex.swg>
|
||||
%include <javascriptcomplex.swg>
|
||||
|
||||
%{
|
||||
#include <complex.h>
|
||||
|
|
|
|||
|
|
@ -9,17 +9,12 @@
|
|||
#define SWIG_SetConstant(name, obj)
|
||||
#define SWIG_Raise(obj, type, desc) SWIG_Javascript_Raise(context, exception, type)
|
||||
|
||||
%include <javascriptfragments.swg>
|
||||
|
||||
/* Include fundamental fragemt definitions */
|
||||
%include <typemaps/fragments.swg>
|
||||
|
||||
/* Python fragments for fundamental types */
|
||||
%include <javascriptprimitives.swg>
|
||||
|
||||
/* override some of the macros in global valtypes.swg */
|
||||
%include <javascriptvaltypes.swg>
|
||||
|
||||
%include <javascriptstrings.swg>
|
||||
|
||||
/* Include the unified typemap library */
|
||||
|
|
|
|||
|
|
@ -1 +0,0 @@
|
|||
|
||||
26
Lib/javascript/v8/ccomplex.i
Normal file
26
Lib/javascript/v8/ccomplex.i
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
/* -----------------------------------------------------------------------------
|
||||
* ccomplex.i
|
||||
*
|
||||
* C complex typemaps
|
||||
* ISO C99: 7.3 Complex arithmetic <complex.h>
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
%include <javscriptcomplex.swg>
|
||||
|
||||
%{
|
||||
#include <complex.h>
|
||||
%}
|
||||
|
||||
|
||||
/* C complex constructor */
|
||||
#define CCplxConst(r, i) ((r) + I*(i))
|
||||
|
||||
%swig_cplxflt_convn(float complex, CCplxConst, creal, cimag);
|
||||
%swig_cplxdbl_convn(double complex, CCplxConst, creal, cimag);
|
||||
%swig_cplxdbl_convn(complex, CCplxConst, creal, cimag);
|
||||
|
||||
/* declaring the typemaps */
|
||||
%typemaps_primitive(SWIG_TYPECHECK_CPLXFLT, float complex);
|
||||
%typemaps_primitive(SWIG_TYPECHECK_CPLXDBL, double complex);
|
||||
%typemaps_primitive(SWIG_TYPECHECK_CPLXDBL, complex);
|
||||
6
Lib/javascript/v8/complex.i
Normal file
6
Lib/javascript/v8/complex.i
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
#ifdef __cplusplus
|
||||
%include <std_complex.i>
|
||||
#else
|
||||
%include <ccomplex.i>
|
||||
#endif
|
||||
|
||||
|
|
@ -4,12 +4,16 @@
|
|||
* Javascript typemaps
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
%include <typemaps/swigmacros.swg>
|
||||
|
||||
%include <javascripttypemaps.swg>
|
||||
|
||||
%include <javascriptruntime.swg>
|
||||
|
||||
%include <javascripthelpers.swg>
|
||||
|
||||
%include <javascriptprimitives.swg>
|
||||
|
||||
%include <javascriptkw.swg>
|
||||
|
||||
%include <javascriptcode.swg>
|
||||
|
||||
%include <javascriptinit.swg>
|
||||
146
Lib/javascript/v8/javascriptcomplex.swg
Normal file
146
Lib/javascript/v8/javascriptcomplex.swg
Normal file
|
|
@ -0,0 +1,146 @@
|
|||
/*
|
||||
Defines the As/From converters for double/float complex, you need to
|
||||
provide complex Type, the Name you want to use in the converters,
|
||||
the complex Constructor method, and the Real and Imag complex
|
||||
accessor methods.
|
||||
|
||||
See the std_complex.i and ccomplex.i for concret examples.
|
||||
*/
|
||||
|
||||
/* the common from converter */
|
||||
%define %swig_fromcplx_conv(Type, Real, Imag)
|
||||
%fragment(SWIG_From_frag(Type),"header",
|
||||
fragment=SWIG_From_frag(double))
|
||||
{
|
||||
SWIGINTERNINLINE JSObjectRef
|
||||
SWIG_From_dec(Type)(%ifcplusplus(const Type&, Type) c)
|
||||
{
|
||||
JSValueRef vals[2];
|
||||
vals[0] = SWIG_From(double)(Real(c));
|
||||
vals[1] = SWIG_From(double)(Imag(c));
|
||||
return JSObjectMakeArray(context, 2, vals, NULL);
|
||||
}
|
||||
}
|
||||
%enddef
|
||||
|
||||
/* the double case */
|
||||
%define %swig_cplxdbl_conv(Type, Constructor, Real, Imag)
|
||||
%fragment(SWIG_AsVal_frag(Type),"header",
|
||||
fragment=SWIG_AsVal_frag(double))
|
||||
{
|
||||
SWIGINTERN int
|
||||
SWIG_AsVal_dec(Type) (JSValueRef o, Type* val)
|
||||
{
|
||||
if (JSValueIsObject(context, o)) {
|
||||
JSObjectRef array;
|
||||
JSValueRef exception, js_re, js_im;
|
||||
double re, im;
|
||||
int res;
|
||||
|
||||
exception = 0;
|
||||
res = 0;
|
||||
|
||||
array = JSValueToObject(context, o, &exception);
|
||||
if(exception != 0)
|
||||
return SWIG_TypeError;
|
||||
|
||||
js_re = JSObjectGetPropertyAtIndex(context, array, 0, &exception);
|
||||
if(exception != 0)
|
||||
return SWIG_TypeError;
|
||||
|
||||
js_im = JSObjectGetPropertyAtIndex(context, array, 1, &exception);
|
||||
if(exception != 0)
|
||||
return SWIG_TypeError;
|
||||
|
||||
res = SWIG_AsVal(double)(js_re, &re);
|
||||
if(!SWIG_IsOK(res)) {
|
||||
return SWIG_TypeError;
|
||||
}
|
||||
|
||||
res = SWIG_AsVal(double)(js_im, &im);
|
||||
if(!SWIG_IsOK(res)) {
|
||||
return SWIG_TypeError;
|
||||
}
|
||||
|
||||
if (val) *val = Constructor(re, im);
|
||||
return SWIG_OK;
|
||||
} else {
|
||||
double d;
|
||||
int res = SWIG_AddCast(SWIG_AsVal(double)(o, &d));
|
||||
if (SWIG_IsOK(res)) {
|
||||
if (val) *val = Constructor(d, 0.0);
|
||||
return res;
|
||||
}
|
||||
}
|
||||
return SWIG_TypeError;
|
||||
}
|
||||
}
|
||||
%swig_fromcplx_conv(Type, Real, Imag);
|
||||
%enddef
|
||||
|
||||
/* the float case */
|
||||
%define %swig_cplxflt_conv(Type, Constructor, Real, Imag)
|
||||
%fragment(SWIG_AsVal_frag(Type),"header",
|
||||
fragment=SWIG_AsVal_frag(float)) {
|
||||
SWIGINTERN int
|
||||
SWIG_AsVal_dec(Type)(JSValueRef o, Type *val)
|
||||
{
|
||||
if (JSValueIsObject(context, o)) {
|
||||
JSObjectRef array;
|
||||
JSValueRef exception, js_re, js_im;
|
||||
double re, im;
|
||||
int res;
|
||||
|
||||
exception = 0;
|
||||
res = 0;
|
||||
|
||||
array = JSValueToObject(context, o, &exception);
|
||||
if(exception != 0)
|
||||
return SWIG_TypeError;
|
||||
|
||||
js_re = JSObjectGetPropertyAtIndex(context, array, 0, &exception);
|
||||
if(exception != 0)
|
||||
return SWIG_TypeError;
|
||||
|
||||
js_im = JSObjectGetPropertyAtIndex(context, array, 1, &exception);
|
||||
if(exception != 0)
|
||||
return SWIG_TypeError;
|
||||
|
||||
res = SWIG_AsVal(double)(js_re, &re);
|
||||
if(!SWIG_IsOK(res)) {
|
||||
return SWIG_TypeError;
|
||||
}
|
||||
|
||||
res = SWIG_AsVal(double)(js_im, &im);
|
||||
if(!SWIG_IsOK(res)) {
|
||||
return SWIG_TypeError;
|
||||
}
|
||||
|
||||
if ((-FLT_MAX <= re && re <= FLT_MAX) && (-FLT_MAX <= im && im <= FLT_MAX)) {
|
||||
if (val) *val = Constructor(%numeric_cast(re, float),
|
||||
%numeric_cast(im, float));
|
||||
return SWIG_OK;
|
||||
} else {
|
||||
return SWIG_OverflowError;
|
||||
}
|
||||
} else {
|
||||
float re;
|
||||
int res = SWIG_AddCast(SWIG_AsVal(float)(o, &re));
|
||||
if (SWIG_IsOK(res)) {
|
||||
if (val) *val = Constructor(re, 0.0);
|
||||
return res;
|
||||
}
|
||||
}
|
||||
return SWIG_TypeError;
|
||||
}
|
||||
}
|
||||
|
||||
%swig_fromcplx_conv(Type, Real, Imag);
|
||||
%enddef
|
||||
|
||||
#define %swig_cplxflt_convn(Type, Constructor, Real, Imag) \
|
||||
%swig_cplxflt_conv(Type, Constructor, Real, Imag)
|
||||
|
||||
|
||||
#define %swig_cplxdbl_convn(Type, Constructor, Real, Imag) \
|
||||
%swig_cplxdbl_conv(Type, Constructor, Real, Imag)
|
||||
15
Lib/javascript/v8/javascriptinit.swg
Normal file
15
Lib/javascript/v8/javascriptinit.swg
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
%insert(init) %{
|
||||
SWIGRUNTIME void
|
||||
SWIG_V8_SetModule(swig_module_info *swig_module) {}
|
||||
|
||||
SWIGRUNTIME swig_module_info *
|
||||
SWIG_V8_GetModule(void) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
#define SWIG_GetModule(clientdata) SWIG_V8_GetModule()
|
||||
#define SWIG_SetModule(clientdata, pointer) SWIG_V8_SetModule(pointer)
|
||||
|
||||
%}
|
||||
|
||||
%insert(init) "swiginit.swg"
|
||||
|
|
@ -1,119 +1,109 @@
|
|||
%typemap(in) bool
|
||||
%{ $1 = ($1_ltype) $input->BooleanValue();%}
|
||||
|
||||
// Primitive types
|
||||
%typemap(in) char,
|
||||
signed char,
|
||||
unsigned char,
|
||||
short,
|
||||
unsigned short,
|
||||
int
|
||||
%{ $1 = ($1_ltype) $input->Int32Value();%}
|
||||
|
||||
%typemap(in) unsigned int,
|
||||
long,
|
||||
unsigned long,
|
||||
long long,
|
||||
unsigned long long
|
||||
%{ $1 = ($1_ltype) $input->UInt32Value();%}
|
||||
|
||||
%typemap(in) float, double
|
||||
%{ $1 = ($1_ltype) $input->NumberValue();%}
|
||||
|
||||
|
||||
%typemap(in) const bool &, bool &,
|
||||
const char &, char &,
|
||||
const signed char &, signed char &,
|
||||
const unsigned char &, unsigned char &,
|
||||
const short &, short &,
|
||||
const unsigned short &, unsigned short &,
|
||||
const int &, int &,
|
||||
const unsigned int &, unsigned int &,
|
||||
const long &, long &,
|
||||
const unsigned long &, unsigned long &,
|
||||
const long long &, long long &,
|
||||
const unsigned long long &, unsigned long long &,
|
||||
const float &, float &,
|
||||
const double &, double &
|
||||
%{
|
||||
// TODO: typemap(in) const bool& at al
|
||||
%fragment(SWIG_From_frag(bool),"header") {
|
||||
SWIGINTERNINLINE
|
||||
v8::Handle<v8::Value>
|
||||
SWIG_From_dec(bool)(bool value)
|
||||
{
|
||||
return v8::Boolean::New(value);
|
||||
}
|
||||
}
|
||||
|
||||
%typemap(out) bool
|
||||
%{ $result = v8::Boolean::New($1);%}
|
||||
%fragment(SWIG_AsVal_frag(bool),"header",
|
||||
fragment=SWIG_AsVal_frag(long)) {
|
||||
SWIGINTERN
|
||||
int SWIG_AsVal_dec(bool)(v8::Handle<v8::Value> obj, bool *val)
|
||||
{
|
||||
if(!obj->IsBoolean()) {
|
||||
return SWIG_ERROR;
|
||||
}
|
||||
|
||||
if (val) *val = obj->BooleanValue();
|
||||
return SWIG_OK;
|
||||
}
|
||||
}
|
||||
|
||||
%typemap(out) char,
|
||||
signed char,
|
||||
unsigned char,
|
||||
short,
|
||||
unsigned short,
|
||||
int
|
||||
%{ $result = v8::Int32::New($1);%}
|
||||
|
||||
%typemap(out) unsigned int,
|
||||
long,
|
||||
unsigned long,
|
||||
long long,
|
||||
unsigned long long
|
||||
%{ $result = v8::UInt32::New($1);%}
|
||||
%fragment(SWIG_From_frag(int),"header") {
|
||||
SWIGINTERNINLINE
|
||||
v8::Handle<v8::Value> SWIG_From_dec(int)(int value)
|
||||
{
|
||||
return v8::Int32::New(value);
|
||||
}
|
||||
}
|
||||
|
||||
%typemap(out) float, double
|
||||
%{ $result = v8::Number::New($1); %}
|
||||
%fragment(SWIG_From_frag(long),"header") {
|
||||
SWIGINTERNINLINE
|
||||
v8::Handle<v8::Value> SWIG_From_dec(long)(long value)
|
||||
{
|
||||
return v8::Integer::New(value);
|
||||
}
|
||||
}
|
||||
|
||||
%typemap(out) const bool &, bool &
|
||||
%{ $result = v8::Boolean::New((*$1);%}
|
||||
%fragment(SWIG_AsVal_frag(long),"header",
|
||||
fragment="SWIG_CanCastAsInteger") {
|
||||
SWIGINTERN
|
||||
int SWIG_AsVal_dec(long)(v8::Handle<v8::Value> obj, long* val)
|
||||
{
|
||||
if (!obj->IsInteger()) {
|
||||
return SWIG_TypeError;
|
||||
}
|
||||
if(val) *val = (long) obj->IntegerValue();
|
||||
|
||||
return SWIG_OK;
|
||||
}
|
||||
}
|
||||
|
||||
%typemap(out) const char &, char &,
|
||||
const signed char &, signed char &,
|
||||
const unsigned char &, unsigned char &,
|
||||
const short &, short &,
|
||||
const unsigned short &, unsigned short &,
|
||||
const int &, int &
|
||||
%{ $result = v8::Int32::New((*$1);%}
|
||||
|
||||
%typemap(out) const unsigned int &, unsigned int &,
|
||||
const long &, long &,
|
||||
const unsigned long &, unsigned long &,
|
||||
const long long &, long long &,
|
||||
const unsigned long long &, unsigned long long &
|
||||
%{ $result = v8::UInt32::New(*$1);%}
|
||||
/* unsigned long */
|
||||
|
||||
%typemap(out) const float &, float &,
|
||||
const double &, double &
|
||||
%{ $result = v8::Number::New(*$1);%}
|
||||
%fragment(SWIG_From_frag(unsigned long),"header",
|
||||
fragment=SWIG_From_frag(long)) {
|
||||
SWIGINTERNINLINE
|
||||
v8::Handle<v8::Value> SWIG_From_dec(unsigned long)(unsigned long value)
|
||||
{
|
||||
return (value > LONG_MAX) ?
|
||||
v8::Integer::NewFromUnsigned(value) : v8::Integer::New(%numeric_cast(value,long));
|
||||
}
|
||||
}
|
||||
|
||||
%typemap(in) short *,
|
||||
unsigned short *,
|
||||
int *,
|
||||
unsigned int *,
|
||||
long *,
|
||||
unsigned long *,
|
||||
long long *,
|
||||
unsigned long long *,
|
||||
float *,
|
||||
double *
|
||||
%{
|
||||
// TODO: typemap(in): short* et al.
|
||||
%}
|
||||
%fragment(SWIG_AsVal_frag(unsigned long),"header",
|
||||
fragment="SWIG_CanCastAsInteger") {
|
||||
SWIGINTERN
|
||||
int SWIG_AsVal_dec(unsigned long)(v8::Handle<v8::Value> obj, unsigned long *val)
|
||||
{
|
||||
if(!obj->IsNumber()) {
|
||||
return SWIG_TypeError;
|
||||
}
|
||||
|
||||
long longVal = (long) obj->NumberValue();
|
||||
|
||||
if(longVal < 0) {
|
||||
return SWIG_OverflowError;
|
||||
}
|
||||
|
||||
if(val) *val = longVal;
|
||||
|
||||
return SWIG_OK;
|
||||
}
|
||||
}
|
||||
|
||||
%fragment(SWIG_From_frag(double),"header") {
|
||||
SWIGINTERN
|
||||
v8::Handle<v8::Value> SWIG_From_dec(double) (double val)
|
||||
{
|
||||
return v8::Number::New(val);
|
||||
}
|
||||
}
|
||||
|
||||
%typemap(out) short *,
|
||||
unsigned short *,
|
||||
int *,
|
||||
unsigned int *,
|
||||
long *,
|
||||
unsigned long *,
|
||||
long long *,
|
||||
unsigned long long *,
|
||||
float *,
|
||||
double *
|
||||
%{
|
||||
// TODO: typemap(out) short* et al.
|
||||
%}
|
||||
|
||||
%typemap(out) void
|
||||
%{ $result = v8::Undefined(); %}
|
||||
|
||||
%fragment(SWIG_AsVal_frag(double),"header") {
|
||||
SWIGINTERN
|
||||
int SWIG_AsVal_dec(double)(v8::Handle<v8::Value> obj, double *val)
|
||||
{
|
||||
if(!obj->IsNumber()) {
|
||||
return SWIG_TypeError;
|
||||
}
|
||||
if(val) *val = obj->NumberValue();
|
||||
|
||||
return SWIG_OK;
|
||||
}
|
||||
}
|
||||
|
||||
%typemap(in) char *
|
||||
%{
|
||||
|
|
@ -121,81 +111,3 @@
|
|||
$1 = *_$1;
|
||||
%}
|
||||
|
||||
%typemap(out) char *
|
||||
%{
|
||||
// TODO: output typemap for char*
|
||||
%}
|
||||
|
||||
%typemap(in) char *& ($*1_ltype temp = 0) %{
|
||||
// TODO: input typemap for char*&
|
||||
%}
|
||||
|
||||
%typemap(out) char *&
|
||||
%{
|
||||
// TODO: output typemap for char*&
|
||||
%}
|
||||
|
||||
/* char arrays - treat as String */
|
||||
%typemap(in) char[ANY], char[] %{
|
||||
// TODO: input typemap for char[]
|
||||
%}
|
||||
|
||||
%typemap(out) char[ANY], char[]
|
||||
%{
|
||||
// TODO: output typemap for char[]
|
||||
%}
|
||||
|
||||
%typemap(freearg) char *, char *&, char[ANY], char[] //TODO: Not working: A memory leak
|
||||
%{
|
||||
// TODO: freearg char* et al
|
||||
%}
|
||||
|
||||
/* Typemaps for composite types */
|
||||
%typemap(in) SWIGTYPE ($&1_type argp) // Objects passed by value, convert to a pointer
|
||||
%{
|
||||
// TODO: input typemap for composite types
|
||||
%}
|
||||
|
||||
%typemap(out) SWIGTYPE ($&1_type temp)
|
||||
%{
|
||||
// TODO: output typemap for composite types
|
||||
%}
|
||||
|
||||
%typemap(in) SWIGTYPE *, SWIGTYPE &
|
||||
%{
|
||||
// TODO: input typemap for ptr types
|
||||
%}
|
||||
|
||||
%typemap(out) SWIGTYPE *, SWIGTYPE &
|
||||
%{
|
||||
// TODO: output typemap for ptr types
|
||||
%}
|
||||
|
||||
// TODO: sanity check?
|
||||
%typemap(arginit) SWIGTYPE *
|
||||
%{%}
|
||||
|
||||
%typemap(in) SWIGTYPE (CLASS::*) ""
|
||||
|
||||
%typemap(out) SWIGTYPE (CLASS::*)
|
||||
%{
|
||||
// TODO: output typemap for CLASS::*
|
||||
%}
|
||||
|
||||
// Default array handling
|
||||
%typemap(in) SWIGTYPE [] %{
|
||||
// TODO: typemap for arrays;
|
||||
%}
|
||||
|
||||
%typemap(out) SWIGTYPE [] %{ $result = $1; %}
|
||||
|
||||
// Some ANSI C typemaps */
|
||||
%apply unsigned long { size_t };
|
||||
|
||||
%apply const unsigned long & { const size_t & };
|
||||
|
||||
// Array reference typemaps
|
||||
%apply SWIGTYPE & { SWIGTYPE ((&)[ANY]) }
|
||||
|
||||
// const pointers
|
||||
%apply SWIGTYPE * { SWIGTYPE *const }
|
||||
|
|
|
|||
|
|
@ -7,3 +7,93 @@
|
|||
%insert(runtime) %{
|
||||
#include <v8.h>
|
||||
%}
|
||||
|
||||
%insert(runtime) "swigrun.swg"; /* SWIG API */
|
||||
%insert(runtime) "swigerrors.swg"; /* SWIG errors */
|
||||
|
||||
%insert(runtime) %{
|
||||
#define SWIG_Error(code, msg) SWIG_V8_exception(code, msg)
|
||||
#define SWIG_exception(code, msg) SWIG_V8_exception(code, msg)
|
||||
#define SWIG_fail goto fail
|
||||
%}
|
||||
|
||||
%insert(runtime) %{
|
||||
typedef struct {
|
||||
bool swigCMemOwn;
|
||||
void *swigCObject;
|
||||
swig_type_info *info;
|
||||
}SWIG_PRV_DATA;
|
||||
%}
|
||||
|
||||
%insert(runtime) %{
|
||||
|
||||
void SWIG_V8_Raise(const char* type) {
|
||||
// TODO: throw v8 exception
|
||||
}
|
||||
|
||||
void SWIG_V8_exception(int code, const char* msg) {
|
||||
SWIG_V8_Raise(msg);
|
||||
}
|
||||
|
||||
%}
|
||||
|
||||
|
||||
%insert(runtime) %{
|
||||
int SWIG_JSC_ConvertInstancePtr(v8::Handle<v8::Object> objRef, void** ptr, swig_type_info *info, int flags) {
|
||||
|
||||
if(objRef->InternalFieldCount() < 1) {
|
||||
return SWIG_ERROR;
|
||||
}
|
||||
Handle<Value> cdataRef = objRef->GetInternalField(0);
|
||||
|
||||
SWIG_PRV_DATA *cdata = (SWIG_PRV_DATA *) v8::External::Unwrap(cdataRef);
|
||||
if(cdata == NULL) {
|
||||
return SWIG_ERROR;
|
||||
}
|
||||
|
||||
if(cdata->info != info) {
|
||||
bool type_valid = false;
|
||||
swig_cast_info *t = info->cast;
|
||||
while(t != NULL) {
|
||||
if(t->type == cdata->info) {
|
||||
type_valid = true;
|
||||
break;
|
||||
}
|
||||
t = t->next;
|
||||
}
|
||||
if(!type_valid) {
|
||||
return SWIG_TypeError;
|
||||
}
|
||||
}
|
||||
|
||||
*ptr = cdata->swigCObject;
|
||||
|
||||
if(flags & SWIG_POINTER_DISOWN) {
|
||||
cdata->swigCMemOwn = false;
|
||||
}
|
||||
|
||||
return SWIG_OK;
|
||||
}
|
||||
|
||||
int SWIG_V8_ConvertPtr(v8::Handle<v8::Value> valRef, void** ptr, swig_type_info *info, int flags) {
|
||||
if(!valRef->IsObject()) {
|
||||
return SWIG_TypeError;
|
||||
}
|
||||
|
||||
v8::Handle<v8::object> objRef = valRef->ToObject();
|
||||
|
||||
return SWIG_V8_ConvertInstancePtr(context, objRef, ptr, info, flags);
|
||||
}
|
||||
|
||||
v8::Handle<v8::Object> SWIG_V8_NewPointerObj(void *ptr, swig_type_info *info, int flags) {
|
||||
// TODO: wrap ptr into an v8 object
|
||||
return 0;
|
||||
}
|
||||
|
||||
#define SWIG_ConvertPtr(obj, ptr, info, flags) SWIG_V8_ConvertPtr(obj, ptr, info, flags)
|
||||
#define SWIG_NewPointerObj(ptr, info, flags) SWIG_V8_NewPointerObj(ptr, info, flags)
|
||||
|
||||
#define SWIG_ConvertInstance(obj, pptr, type, flags) SWIG_V8_ConvertInstancePtr(obj, pptr, type, flags)
|
||||
#define SWIG_NewInstanceObj(thisvalue, type, flags) SWIG_V8_NewPointerObj(thisvalue, type, flags)
|
||||
|
||||
%}
|
||||
|
|
|
|||
16
Lib/javascript/v8/javascripttypemaps.swg
Normal file
16
Lib/javascript/v8/javascripttypemaps.swg
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
#define SWIG_Object v8::Handle<v8::Value>
|
||||
#define VOID_Object v8::Undefined()
|
||||
#define SWIG_AppendOutput(result, obj)
|
||||
#define SWIG_SetConstant(name, obj)
|
||||
#define SWIG_Raise(obj, type, desc) SWIG_V8_Raise(type)
|
||||
|
||||
/* Include fundamental fragemt definitions */
|
||||
%include <typemaps/fragments.swg>
|
||||
|
||||
/* Python fragments for fundamental types */
|
||||
%include <javascriptprimitives.swg>
|
||||
|
||||
%include <javascriptstrings.swg>
|
||||
|
||||
/* Include the unified typemap library */
|
||||
%include <typemaps/swigtypemaps.swg>
|
||||
5
Lib/javascript/v8/std_common.i
Executable file
5
Lib/javascript/v8/std_common.i
Executable file
|
|
@ -0,0 +1,5 @@
|
|||
%include <std_except.i>
|
||||
|
||||
%apply size_t { std::size_t };
|
||||
%apply const size_t& { const std::size_t& };
|
||||
|
||||
19
Lib/javascript/v8/std_complex.i
Normal file
19
Lib/javascript/v8/std_complex.i
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
/*
|
||||
* STD C++ complex typemaps
|
||||
*/
|
||||
|
||||
%include <javascriptcomplex.swg>
|
||||
|
||||
%{
|
||||
#include <complex>
|
||||
%}
|
||||
|
||||
/* defining the complex as/from converters */
|
||||
|
||||
%swig_cplxdbl_convn(std::complex<double>, std::complex<double>, std::real, std::imag)
|
||||
%swig_cplxflt_convn(std::complex<float>, std::complex<float>, std::real, std::imag)
|
||||
|
||||
/* defining the typemaps */
|
||||
|
||||
%typemaps_primitive(%checkcode(CPLXDBL), std::complex<double>);
|
||||
%typemaps_primitive(%checkcode(CPLXFLT), std::complex<float>);
|
||||
1
Lib/javascript/v8/std_except.i
Normal file
1
Lib/javascript/v8/std_except.i
Normal file
|
|
@ -0,0 +1 @@
|
|||
%include <typemaps/std_except.swg>
|
||||
74
Lib/javascript/v8/std_map.i
Executable file
74
Lib/javascript/v8/std_map.i
Executable file
|
|
@ -0,0 +1,74 @@
|
|||
/* -----------------------------------------------------------------------------
|
||||
* std_map.i
|
||||
*
|
||||
* SWIG typemaps for std::map
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
%include <std_common.i>
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// std::map
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
%{
|
||||
#include <map>
|
||||
#include <algorithm>
|
||||
#include <stdexcept>
|
||||
%}
|
||||
|
||||
// exported class
|
||||
|
||||
namespace std {
|
||||
|
||||
template<class K, class T> class map {
|
||||
// add typemaps here
|
||||
public:
|
||||
typedef size_t size_type;
|
||||
typedef ptrdiff_t difference_type;
|
||||
typedef K key_type;
|
||||
typedef T mapped_type;
|
||||
map();
|
||||
map(const map<K,T> &);
|
||||
|
||||
unsigned int size() const;
|
||||
bool empty() const;
|
||||
void clear();
|
||||
%extend {
|
||||
const T& get(const K& key) throw (std::out_of_range) {
|
||||
std::map<K,T >::iterator i = self->find(key);
|
||||
if (i != self->end())
|
||||
return i->second;
|
||||
else
|
||||
throw std::out_of_range("key not found");
|
||||
}
|
||||
void set(const K& key, const T& x) {
|
||||
(*self)[key] = x;
|
||||
}
|
||||
void del(const K& key) throw (std::out_of_range) {
|
||||
std::map<K,T >::iterator i = self->find(key);
|
||||
if (i != self->end())
|
||||
self->erase(i);
|
||||
else
|
||||
throw std::out_of_range("key not found");
|
||||
}
|
||||
bool has_key(const K& key) {
|
||||
std::map<K,T >::iterator i = self->find(key);
|
||||
return i != self->end();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Legacy macros (deprecated)
|
||||
%define specialize_std_map_on_key(K,CHECK,CONVERT_FROM,CONVERT_TO)
|
||||
#warning "specialize_std_map_on_key ignored - macro is deprecated and no longer necessary"
|
||||
%enddef
|
||||
|
||||
%define specialize_std_map_on_value(T,CHECK,CONVERT_FROM,CONVERT_TO)
|
||||
#warning "specialize_std_map_on_value ignored - macro is deprecated and no longer necessary"
|
||||
%enddef
|
||||
|
||||
%define specialize_std_map_on_both(K,CHECK_K,CONVERT_K_FROM,CONVERT_K_TO, T,CHECK_T,CONVERT_T_FROM,CONVERT_T_TO)
|
||||
#warning "specialize_std_map_on_both ignored - macro is deprecated and no longer necessary"
|
||||
%enddef
|
||||
|
||||
}
|
||||
34
Lib/javascript/v8/std_pair.i
Executable file
34
Lib/javascript/v8/std_pair.i
Executable file
|
|
@ -0,0 +1,34 @@
|
|||
/* -----------------------------------------------------------------------------
|
||||
* std_pair.i
|
||||
*
|
||||
* SWIG typemaps for std::pair
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
%include <std_common.i>
|
||||
%include <exception.i>
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// std::pair
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
%{
|
||||
#include <utility>
|
||||
%}
|
||||
|
||||
namespace std {
|
||||
|
||||
template<class T, class U> struct pair {
|
||||
|
||||
pair();
|
||||
pair(T first, U second);
|
||||
pair(const pair& p);
|
||||
|
||||
template <class U1, class U2> pair(const pair<U1, U2> &p);
|
||||
|
||||
T first;
|
||||
U second;
|
||||
};
|
||||
|
||||
// add specializations here
|
||||
|
||||
}
|
||||
85
Lib/javascript/v8/std_vector.i
Executable file
85
Lib/javascript/v8/std_vector.i
Executable file
|
|
@ -0,0 +1,85 @@
|
|||
/* -----------------------------------------------------------------------------
|
||||
* std_vector.i
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
%include <std_common.i>
|
||||
|
||||
%{
|
||||
#include <vector>
|
||||
#include <stdexcept>
|
||||
%}
|
||||
|
||||
namespace std {
|
||||
|
||||
template<class T> class vector {
|
||||
public:
|
||||
typedef size_t size_type;
|
||||
typedef T value_type;
|
||||
typedef const value_type& const_reference;
|
||||
vector();
|
||||
vector(size_type n);
|
||||
size_type size() const;
|
||||
size_type capacity() const;
|
||||
void reserve(size_type n);
|
||||
%rename(isEmpty) empty;
|
||||
bool empty() const;
|
||||
void clear();
|
||||
%rename(add) push_back;
|
||||
void push_back(const value_type& x);
|
||||
%extend {
|
||||
const_reference get(int i) throw (std::out_of_range) {
|
||||
int size = int(self->size());
|
||||
if (i>=0 && i<size)
|
||||
return (*self)[i];
|
||||
else
|
||||
throw std::out_of_range("vector index out of range");
|
||||
}
|
||||
void set(int i, const value_type& val) throw (std::out_of_range) {
|
||||
int size = int(self->size());
|
||||
if (i>=0 && i<size)
|
||||
(*self)[i] = val;
|
||||
else
|
||||
throw std::out_of_range("vector index out of range");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// bool specialization
|
||||
template<> class vector<bool> {
|
||||
public:
|
||||
typedef size_t size_type;
|
||||
typedef bool value_type;
|
||||
typedef bool const_reference;
|
||||
vector();
|
||||
vector(size_type n);
|
||||
size_type size() const;
|
||||
size_type capacity() const;
|
||||
void reserve(size_type n);
|
||||
%rename(isEmpty) empty;
|
||||
bool empty() const;
|
||||
void clear();
|
||||
%rename(add) push_back;
|
||||
void push_back(const value_type& x);
|
||||
%extend {
|
||||
const_reference get(int i) throw (std::out_of_range) {
|
||||
int size = int(self->size());
|
||||
if (i>=0 && i<size)
|
||||
return (*self)[i];
|
||||
else
|
||||
throw std::out_of_range("vector index out of range");
|
||||
}
|
||||
void set(int i, const value_type& val) throw (std::out_of_range) {
|
||||
int size = int(self->size());
|
||||
if (i>=0 && i<size)
|
||||
(*self)[i] = val;
|
||||
else
|
||||
throw std::out_of_range("vector index out of range");
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
%define specialize_std_vector(T)
|
||||
#warning "specialize_std_vector - specialization for type T no longer needed"
|
||||
%enddef
|
||||
|
||||
10
Lib/javascript/v8/stl.i
Executable file
10
Lib/javascript/v8/stl.i
Executable file
|
|
@ -0,0 +1,10 @@
|
|||
/* -----------------------------------------------------------------------------
|
||||
* stl.i
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
%include <std_common.i>
|
||||
%include <std_string.i>
|
||||
%include <std_vector.i>
|
||||
%include <std_map.i>
|
||||
%include <std_pair.i>
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue