1、在conversions.yaml文件添加要绑定的类型转换函数:文件所在目录:

添加的内容如下:

Int1DArray 是我要绑定的结构体。然后绑定要使用的相关文件。(类文件和头文件)

2、新建一个js项目,将绑定好的文件和源文件加入到项目中.(怎么加自己想吧!)

3、修改ScriptingCore类

头文件中声明:

Int1DArray* jsval_to_int1darray(JSContext *cx, jsval v);

类文件中实现:

Int1DArray*jsval_to_int1darray(JSContext *cx, jsval v)

{

JSObject *arr;

if (JS_ValueToObject(cx, v,&arr) && JS_IsArrayObject(cx, arr)) {

uint32_t len = 0;

JS_GetArrayLength(cx, arr, &len);

Int1DArray *int2d=(Int1DArray*)malloc(sizeof(Int1DArray));

int2d->value=(int*)malloc(sizeof(int)*len);

int2d->length=len;

for (int i=0; i < len;i++) {

jsval elt;

int temp;

if (JS_GetElement(cx, arr,i, &elt) && JS_ValueToInt32(cx, elt, &temp)) {

int2d->value[i]= temp;

}

}

return int2d;

}

returnNULL;

}

4、在hello.js中找个合适的位置测试代码:

varmysqlite=sql.MySQLite.create('cgw.db');

if(mysqlite.open()){

mysqlite.createTable("UserInfo","(ID intprimary key , UserName char, PassWord char)");

mysqlite.insert("UserInfo", "(ID,UserName,PassWord)values(1,'kfqcome','123456')");

var a=new Array(1,2,3);

mysqlite.insert("UserInfo", "(ID,UserName,PassWord)values(2,'miss wang','654321')",array);

mysqlite.selectAll("UserInfo");

}