Javascript code formatting corrections
This commit is contained in:
parent
c4d003e442
commit
b6aa39b82a
2 changed files with 15 additions and 21 deletions
|
|
@ -30,38 +30,33 @@
|
||||||
%define JAVASCRIPT_ARRAYS_IN_DECL(NAME, CTYPE, ANY, ANYLENGTH)
|
%define JAVASCRIPT_ARRAYS_IN_DECL(NAME, CTYPE, ANY, ANYLENGTH)
|
||||||
|
|
||||||
%typemap(in, fragment=NAME) CTYPE[ANY] {
|
%typemap(in, fragment=NAME) CTYPE[ANY] {
|
||||||
if ($input->IsArray())
|
if ($input->IsArray()) {
|
||||||
{
|
|
||||||
// Convert into Array
|
// Convert into Array
|
||||||
v8::Local<v8::Array> array = v8::Local<v8::Array>::Cast($input);
|
v8::Local<v8::Array> array = v8::Local<v8::Array>::Cast($input);
|
||||||
|
|
||||||
int length = ANYLENGTH;
|
int length = ANYLENGTH;
|
||||||
|
|
||||||
$1 = ($*1_ltype *)malloc(sizeof($*1_ltype) * length);
|
$1 = ($*1_ltype *)malloc(sizeof($*1_ltype) * length);
|
||||||
|
|
||||||
// Get each element from array
|
// Get each element from array
|
||||||
for (int i = 0; i < length; i++)
|
for (int i = 0; i < length; i++) {
|
||||||
{
|
|
||||||
v8::Local<v8::Value> jsvalue = SWIGV8_ARRAY_GET(array, i);
|
v8::Local<v8::Value> jsvalue = SWIGV8_ARRAY_GET(array, i);
|
||||||
$*1_ltype temp;
|
$*1_ltype temp;
|
||||||
|
|
||||||
// Get primitive value from JSObject
|
// Get primitive value from JSObject
|
||||||
int res = SWIG_AsVal(CTYPE)(jsvalue, &temp);
|
int res = SWIG_AsVal(CTYPE)(jsvalue, &temp);
|
||||||
if (!SWIG_IsOK(res))
|
if (!SWIG_IsOK(res)) {
|
||||||
{
|
|
||||||
SWIG_exception_fail(SWIG_ERROR, "Failed to convert $input to double");
|
SWIG_exception_fail(SWIG_ERROR, "Failed to convert $input to double");
|
||||||
}
|
}
|
||||||
arg$argnum[i] = temp;
|
arg$argnum[i] = temp;
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
SWIG_exception_fail(SWIG_ERROR, "$input is not an array");
|
SWIG_exception_fail(SWIG_ERROR, "$input is not an array");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
%typemap(freearg) CTYPE[ANY] {
|
%typemap(freearg) CTYPE[ANY] {
|
||||||
free($1);
|
free($1);
|
||||||
}
|
}
|
||||||
|
|
||||||
%enddef
|
%enddef
|
||||||
|
|
@ -72,8 +67,7 @@
|
||||||
int length = $1_dim0;
|
int length = $1_dim0;
|
||||||
v8::Local<v8::Array> array = SWIGV8_ARRAY_NEW(length);
|
v8::Local<v8::Array> array = SWIGV8_ARRAY_NEW(length);
|
||||||
|
|
||||||
for (int i = 0; i < length; i++)
|
for (int i = 0; i < length; i++) {
|
||||||
{
|
|
||||||
SWIGV8_ARRAY_SET(array, i, SWIG_From(CTYPE)($1[i]));
|
SWIGV8_ARRAY_SET(array, i, SWIG_From(CTYPE)($1[i]));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -39,23 +39,23 @@ SWIG_AsVal_dec(Type) (SWIGV8_VALUE o, Type* val)
|
||||||
if (o->IsArray()) {
|
if (o->IsArray()) {
|
||||||
SWIGV8_ARRAY array = SWIGV8_ARRAY::Cast(o);
|
SWIGV8_ARRAY array = SWIGV8_ARRAY::Cast(o);
|
||||||
|
|
||||||
if(array->Length() != 2) SWIG_Error(SWIG_TypeError, "Illegal argument for complex: must be array[2].");
|
if (array->Length() != 2) SWIG_Error(SWIG_TypeError, "Illegal argument for complex: must be array[2].");
|
||||||
double re, im;
|
double re, im;
|
||||||
int res;
|
int res;
|
||||||
|
|
||||||
res = SWIG_AsVal(double)(SWIGV8_ARRAY_GET(array, 0), &re);
|
res = SWIG_AsVal(double)(SWIGV8_ARRAY_GET(array, 0), &re);
|
||||||
if(!SWIG_IsOK(res)) {
|
if (!SWIG_IsOK(res)) {
|
||||||
return SWIG_TypeError;
|
return SWIG_TypeError;
|
||||||
}
|
}
|
||||||
|
|
||||||
res = SWIG_AsVal(double)(SWIGV8_ARRAY_GET(array, 1), &im);
|
res = SWIG_AsVal(double)(SWIGV8_ARRAY_GET(array, 1), &im);
|
||||||
if(!SWIG_IsOK(res)) {
|
if (!SWIG_IsOK(res)) {
|
||||||
return SWIG_TypeError;
|
return SWIG_TypeError;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (val) *val = Constructor(re, im);
|
if (val) *val = Constructor(re, im);
|
||||||
return SWIG_OK;
|
return SWIG_OK;
|
||||||
} else if(o->IsNumber()){
|
} else if (o->IsNumber()) {
|
||||||
double d;
|
double d;
|
||||||
int res = SWIG_AddCast(SWIG_AsVal(double)(o, &d));
|
int res = SWIG_AddCast(SWIG_AsVal(double)(o, &d));
|
||||||
if (SWIG_IsOK(res)) {
|
if (SWIG_IsOK(res)) {
|
||||||
|
|
@ -81,17 +81,17 @@ SWIG_AsVal_dec(Type) (SWIGV8_VALUE o, Type* val)
|
||||||
if (o->IsArray()) {
|
if (o->IsArray()) {
|
||||||
SWIGV8_ARRAY array = SWIGV8_ARRAY::Cast(o);
|
SWIGV8_ARRAY array = SWIGV8_ARRAY::Cast(o);
|
||||||
|
|
||||||
if(array->Length() != 2) SWIG_Error(SWIG_TypeError, "Illegal argument for complex: must be array[2].");
|
if (array->Length() != 2) SWIG_Error(SWIG_TypeError, "Illegal argument for complex: must be array[2].");
|
||||||
double re, im;
|
double re, im;
|
||||||
int res;
|
int res;
|
||||||
|
|
||||||
res = SWIG_AsVal(double)(SWIGV8_ARRAY_GET(array, 0), &re);
|
res = SWIG_AsVal(double)(SWIGV8_ARRAY_GET(array, 0), &re);
|
||||||
if(!SWIG_IsOK(res)) {
|
if (!SWIG_IsOK(res)) {
|
||||||
return SWIG_TypeError;
|
return SWIG_TypeError;
|
||||||
}
|
}
|
||||||
|
|
||||||
res = SWIG_AsVal(double)(SWIGV8_ARRAY_GET(array, 1), &im);
|
res = SWIG_AsVal(double)(SWIGV8_ARRAY_GET(array, 1), &im);
|
||||||
if(!SWIG_IsOK(res)) {
|
if (!SWIG_IsOK(res)) {
|
||||||
return SWIG_TypeError;
|
return SWIG_TypeError;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -102,7 +102,7 @@ SWIG_AsVal_dec(Type) (SWIGV8_VALUE o, Type* val)
|
||||||
} else {
|
} else {
|
||||||
return SWIG_OverflowError;
|
return SWIG_OverflowError;
|
||||||
}
|
}
|
||||||
} else if(o->IsNumber()){
|
} else if (o->IsNumber()) {
|
||||||
float re;
|
float re;
|
||||||
int res = SWIG_AddCast(SWIG_AsVal(float)(o, &re));
|
int res = SWIG_AddCast(SWIG_AsVal(float)(o, &re));
|
||||||
if (SWIG_IsOK(res)) {
|
if (SWIG_IsOK(res)) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue