#ifndef _JSCProxyFunction_h #define _JSCProxyFunction_h namespace laya { template JSValueRef ToJSValue(T t) { return __TransferToJs::ToJs(t); } inline bool checkJSToCArgs(size_t given, size_t expect) { assert(given >= expect); if (given >= expect) return true; static char buff[512]; sprintf(buff, "console.log('arguments number err: %d:%d');var e = new Error();console.log(e.stack);", expect, given); //__JSRun::Run(buff); return false; } #define JS2CCALL_GET_COBJ \ Cls* pThis = (Cls*)JSObjectGetPrivate( thisObject ); #define JS2CCALL_GET_PARAMS1 \ if(!checkJSToCArgs(argumentCount,1))return JSValueMakeUndefined(ctx);\ P1 p1 = __TransferToCpp::ToCpp(arguments[0]); #define JS2CCALL_GET_PARAMS2 \ if(!checkJSToCArgs(argumentCount,2))return JSValueMakeUndefined(ctx);\ P1 p1 = __TransferToCpp::ToCpp(arguments[0]);\ P2 p2 = __TransferToCpp::ToCpp(arguments[1]); #define JS2CCALL_GET_PARAMS3 \ if(!checkJSToCArgs(argumentCount,3))return JSValueMakeUndefined(ctx);\ P1 p1 = __TransferToCpp::ToCpp(arguments[0]);\ P2 p2 = __TransferToCpp::ToCpp(arguments[1]);\ P3 p3 = __TransferToCpp::ToCpp(arguments[2]); #define JS2CCALL_GET_PARAMS4 \ if(!checkJSToCArgs(argumentCount,4))return JSValueMakeUndefined(ctx);\ P1 p1 = __TransferToCpp::ToCpp(arguments[0]);\ P2 p2 = __TransferToCpp::ToCpp(arguments[1]);\ P3 p3 = __TransferToCpp::ToCpp(arguments[2]);\ P4 p4 = __TransferToCpp::ToCpp(arguments[3]); #define JS2CCALL_GET_PARAMS5 \ if(!checkJSToCArgs(argumentCount,5))return JSValueMakeUndefined(ctx);\ P1 p1 = __TransferToCpp::ToCpp(arguments[0]);\ P2 p2 = __TransferToCpp::ToCpp(arguments[1]);\ P3 p3 = __TransferToCpp::ToCpp(arguments[2]);\ P4 p4 = __TransferToCpp::ToCpp(arguments[3]);\ P5 p5 = __TransferToCpp::ToCpp(arguments[4]); #define JS2CCALL_GET_PARAMS6 \ if(!checkJSToCArgs(argumentCount,6))return JSValueMakeUndefined(ctx);\ P1 p1 = __TransferToCpp::ToCpp(arguments[0]);\ P2 p2 = __TransferToCpp::ToCpp(arguments[1]);\ P3 p3 = __TransferToCpp::ToCpp(arguments[2]);\ P4 p4 = __TransferToCpp::ToCpp(arguments[3]);\ P5 p5 = __TransferToCpp::ToCpp(arguments[4]);\ P6 p6 = __TransferToCpp::ToCpp(arguments[5]); #define JS2CCALL_GET_PARAMS7 \ if(!checkJSToCArgs(argumentCount,7))return JSValueMakeUndefined(ctx);\ P1 p1 = __TransferToCpp::ToCpp(arguments[0]);\ P2 p2 = __TransferToCpp::ToCpp(arguments[1]);\ P3 p3 = __TransferToCpp::ToCpp(arguments[2]);\ P4 p4 = __TransferToCpp::ToCpp(arguments[3]);\ P5 p5 = __TransferToCpp::ToCpp(arguments[4]);\ P6 p6 = __TransferToCpp::ToCpp(arguments[5]);\ P7 p7 = __TransferToCpp::ToCpp(arguments[6]); #define JS2CCALL_GET_PARAMS8 \ if(!checkJSToCArgs(argumentCount,8))return JSValueMakeUndefined(ctx);\ P1 p1 = __TransferToCpp::ToCpp(arguments[0]);\ P2 p2 = __TransferToCpp::ToCpp(arguments[1]);\ P3 p3 = __TransferToCpp::ToCpp(arguments[2]);\ P4 p4 = __TransferToCpp::ToCpp(arguments[3]);\ P5 p5 = __TransferToCpp::ToCpp(arguments[4]);\ P6 p6 = __TransferToCpp::ToCpp(arguments[5]);\ P7 p7 = __TransferToCpp::ToCpp(arguments[6]);\ P8 p8 = __TransferToCpp::ToCpp(arguments[7]); #define JS2CCALL_GET_PARAMS9 \ if(!checkJSToCArgs(argumentCount,9))return JSValueMakeUndefined(ctx);\ P1 p1 = __TransferToCpp::ToCpp(arguments[0]);\ P2 p2 = __TransferToCpp::ToCpp(arguments[1]);\ P3 p3 = __TransferToCpp::ToCpp(arguments[2]);\ P4 p4 = __TransferToCpp::ToCpp(arguments[3]);\ P5 p5 = __TransferToCpp::ToCpp(arguments[4]);\ P6 p6 = __TransferToCpp::ToCpp(arguments[5]);\ P7 p7 = __TransferToCpp::ToCpp(arguments[6]);\ P8 p8 = __TransferToCpp::ToCpp(arguments[7]);\ P9 p9 = __TransferToCpp::ToCpp(arguments[8]); #define JS2CCALL_GET_PARAMS11 \ if(!checkJSToCArgs(argumentCount,11))return JSValueMakeUndefined(ctx);\ P1 p1 = __TransferToCpp::ToCpp(arguments[0]);\ P2 p2 = __TransferToCpp::ToCpp(arguments[1]);\ P3 p3 = __TransferToCpp::ToCpp(arguments[2]);\ P4 p4 = __TransferToCpp::ToCpp(arguments[3]);\ P5 p5 = __TransferToCpp::ToCpp(arguments[4]);\ P6 p6 = __TransferToCpp::ToCpp(arguments[5]);\ P7 p7 = __TransferToCpp::ToCpp(arguments[6]);\ P8 p8 = __TransferToCpp::ToCpp(arguments[7]);\ P9 p9 = __TransferToCpp::ToCpp(arguments[8]);\ P10 p10 = __TransferToCpp::ToCpp(arguments[9]);\ P11 p11 = __TransferToCpp::ToCpp(arguments[10]); #define JS2CCALL_GET_PARAMS12 \ if(!checkJSToCArgs(argumentCount,12))return JSValueMakeUndefined(ctx);\ P1 p1 = __TransferToCpp::ToCpp(arguments[0]);\ P2 p2 = __TransferToCpp::ToCpp(arguments[1]);\ P3 p3 = __TransferToCpp::ToCpp(arguments[2]);\ P4 p4 = __TransferToCpp::ToCpp(arguments[3]);\ P5 p5 = __TransferToCpp::ToCpp(arguments[4]);\ P6 p6 = __TransferToCpp::ToCpp(arguments[5]);\ P7 p7 = __TransferToCpp::ToCpp(arguments[6]);\ P8 p8 = __TransferToCpp::ToCpp(arguments[7]);\ P9 p9 = __TransferToCpp::ToCpp(arguments[8]);\ P10 p10 = __TransferToCpp::ToCpp(arguments[9]);\ P11 p11 = __TransferToCpp::ToCpp(arguments[10]);\ P11 p12 = __TransferToCpp::ToCpp(arguments[11]); struct IJSCCallback { virtual ~IJSCCallback(){} virtual JSValueRef call(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception){assert(false);return nullptr;} virtual JSObjectRef constructor(JSContextRef ctx, JSObjectRef constructor, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception){assert(false);return nullptr;} virtual uint16_t getNumArgs() = 0; }; template struct JSCCallback: public IJSCCallback { JSCCallback(T func){} virtual JSValueRef call(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception){ assert(false && "JSCCallback::call not implemented"); return nullptr; } virtual uint16_t getNumArgs() { return 0; } }; template struct JSCCallback :public IJSCCallback{ typedef R(Cls::*F)(void); JSCCallback(F func):m_func(func){} virtual JSValueRef call(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception){ JS2CCALL_GET_COBJ; JSValueRef ret = ToJSValue((pThis->*m_func)()); resetJsStrBuf(); return ret; } virtual uint16_t getNumArgs() { return 0; } F m_func; }; template struct JSCCallback: public IJSCCallback { typedef R(Cls::*F)(P1); JSCCallback(F func):m_func(func){} virtual JSValueRef call(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception){ JS2CCALL_GET_COBJ; JS2CCALL_GET_PARAMS1; JSValueRef ret = ToJSValue((pThis->*m_func)(p1)); resetJsStrBuf(); return ret; } virtual uint16_t getNumArgs() { return 1; } F m_func; }; template//2 struct JSCCallback:public IJSCCallback { typedef R(Cls::*F)(P1, P2); JSCCallback(F func):m_func(func){} virtual JSValueRef call(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception){ JS2CCALL_GET_COBJ; JS2CCALL_GET_PARAMS2; JSValueRef ret = ToJSValue((pThis->*m_func)(p1,p2)); resetJsStrBuf(); return ret; } virtual uint16_t getNumArgs() { return 2; } F m_func; }; template//3 struct JSCCallback:public IJSCCallback { typedef R(Cls::*F)(P1, P2, P3); JSCCallback(F func):m_func(func){} virtual JSValueRef call(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception){ JS2CCALL_GET_COBJ; JS2CCALL_GET_PARAMS3; JSValueRef ret = ToJSValue((pThis->*m_func)(p1, p2,p3)); resetJsStrBuf(); return ret; } virtual uint16_t getNumArgs() { return 3; } F m_func; }; template//4 struct JSCCallback:public IJSCCallback { typedef R(Cls::*F)(P1, P2, P3, P4); JSCCallback(F func):m_func(func){} virtual JSValueRef call(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception){ JS2CCALL_GET_COBJ; JS2CCALL_GET_PARAMS4; JSValueRef ret = ToJSValue((pThis->*m_func)(p1, p2, p3, p4)); resetJsStrBuf(); return ret; } virtual uint16_t getNumArgs() { return 4; } F m_func; }; template//5 struct JSCCallback:public IJSCCallback { typedef R(Cls::*F)(P1, P2, P3, P4, P5); JSCCallback(F func):m_func(func){} virtual JSValueRef call(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception){ JS2CCALL_GET_COBJ; JS2CCALL_GET_PARAMS5; JSValueRef ret = ToJSValue((pThis->*m_func)(p1, p2, p3, p4,p5)); resetJsStrBuf(); return ret; } virtual uint16_t getNumArgs() { return 5; } F m_func; }; template//6 struct JSCCallback:public IJSCCallback { typedef R(Cls::*F)(P1, P2, P3, P4, P5, P6); JSCCallback(F func):m_func(func){} virtual JSValueRef call(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception){ JS2CCALL_GET_COBJ; JS2CCALL_GET_PARAMS6; JSValueRef ret = ToJSValue((pThis->*m_func)(p1, p2, p3, p4, p5,p6)); resetJsStrBuf(); return ret; } virtual uint16_t getNumArgs() { return 6; } F m_func; }; template//7 struct JSCCallback:public IJSCCallback { typedef R(Cls::*F)(P1, P2, P3, P4, P5, P6, P7); JSCCallback(F func):m_func(func){} virtual JSValueRef call(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception){ JS2CCALL_GET_COBJ; JS2CCALL_GET_PARAMS7; JSValueRef ret = ToJSValue((pThis->*m_func)(p1, p2, p3, p4, p5,p7)); resetJsStrBuf(); return ret; } virtual uint16_t getNumArgs() { return 7; } F m_func; }; template//12 struct JSCCallback:public IJSCCallback { typedef R(Cls::*F)(P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12); JSCCallback(F func):m_func(func){} virtual JSValueRef call(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception){ JS2CCALL_GET_COBJ; JS2CCALL_GET_PARAMS12; JSValueRef ret = ToJSValue((pThis->*m_func)(p1, p2, p3, p4, p5, p7, p8, p9, p10, p11, p12)); resetJsStrBuf(); return ret; } virtual uint16_t getNumArgs() { return 12; } F m_func; }; template struct JSCCallback:public IJSCCallback { typedef void(Cls::*F)(void); JSCCallback(F func):m_func(func){} virtual JSValueRef call(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception){ JS2CCALL_GET_COBJ; (pThis->*m_func)(); resetJsStrBuf(); return JSValueMakeUndefined(ctx); } virtual uint16_t getNumArgs() { return 0; } F m_func; }; template< typename P1, typename Cls>//1 struct JSCCallback :public IJSCCallback{ typedef void(Cls::*F)(P1); JSCCallback(F func):m_func(func){} virtual JSValueRef call(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception){ JS2CCALL_GET_COBJ; JS2CCALL_GET_PARAMS1; (pThis->*m_func)(p1); resetJsStrBuf(); return JSValueMakeUndefined(ctx); } virtual uint16_t getNumArgs() { return 1; } F m_func; }; template//2 struct JSCCallback:public IJSCCallback { typedef void(Cls::*F)(P1, P2); JSCCallback(F func):m_func(func){} virtual JSValueRef call(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception){ JS2CCALL_GET_COBJ; JS2CCALL_GET_PARAMS2; (pThis->*m_func)(p1,p2); resetJsStrBuf(); return JSValueMakeUndefined(ctx); } virtual uint16_t getNumArgs() { return 2; } F m_func; }; template//3 struct JSCCallback:public IJSCCallback { typedef void(Cls::*F)(P1, P2, P3); JSCCallback(F func):m_func(func){} virtual JSValueRef call(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception){ JS2CCALL_GET_COBJ; JS2CCALL_GET_PARAMS3; (pThis->*m_func)(p1,p2,p3); resetJsStrBuf(); return JSValueMakeUndefined(ctx); } virtual uint16_t getNumArgs() { return 3; } F m_func; }; template< typename Cls, typename P1, typename P2, typename P3, typename P4>//4 struct JSCCallback:public IJSCCallback { typedef void(Cls::*F)(P1, P2, P3, P4); JSCCallback(F func):m_func(func){} virtual JSValueRef call(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception){ JS2CCALL_GET_COBJ; JS2CCALL_GET_PARAMS4; (pThis->*m_func)(p1, p2, p3, p4); resetJsStrBuf(); return JSValueMakeUndefined(ctx); } virtual uint16_t getNumArgs() { return 4; } F m_func; }; template< typename Cls, typename P1, typename P2, typename P3, typename P4, typename P5>//5 struct JSCCallback:public IJSCCallback { typedef void(Cls::*F)(P1, P2, P3, P4, P5); JSCCallback(F func):m_func(func){} virtual JSValueRef call(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception){ JS2CCALL_GET_COBJ; JS2CCALL_GET_PARAMS5; (pThis->*m_func)(p1, p2, p3, p4, p5); resetJsStrBuf(); return JSValueMakeUndefined(ctx); } virtual uint16_t getNumArgs() { return 5; } F m_func; }; template< typename Cls, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6>//6 struct JSCCallback:public IJSCCallback { typedef void(Cls::*F)(P1, P2, P3, P4, P5, P6); JSCCallback(F func):m_func(func){} virtual JSValueRef call(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception){ JS2CCALL_GET_COBJ; JS2CCALL_GET_PARAMS6; (pThis->*m_func)(p1, p2, p3, p4, p5, p6); resetJsStrBuf(); return JSValueMakeUndefined(ctx); } virtual uint16_t getNumArgs() { return 6; } F m_func; }; template< typename Cls, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7>//7 struct JSCCallback:public IJSCCallback { typedef void(Cls::*F)(P1, P2, P3, P4, P5, P6, P7); JSCCallback(F func):m_func(func){} virtual JSValueRef call(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception){ JS2CCALL_GET_COBJ; JS2CCALL_GET_PARAMS7; (pThis->*m_func)(p1, p2, p3, p4, p5, p6, p7); resetJsStrBuf(); return JSValueMakeUndefined(ctx); } virtual uint16_t getNumArgs() { return 7; } F m_func; }; template< typename Cls, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7, typename P8, typename P9>//9 struct JSCCallback:public IJSCCallback { typedef void(Cls::*F)(P1, P2, P3, P4, P5, P6, P7, P8, P9); JSCCallback(F func):m_func(func){} virtual JSValueRef call(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception){ JS2CCALL_GET_COBJ; JS2CCALL_GET_PARAMS9; (pThis->*m_func)(p1, p2, p3, p4, p5, p6, p7, p8, p9); resetJsStrBuf(); return JSValueMakeUndefined(ctx); } virtual uint16_t getNumArgs() { return 9; } F m_func; }; template< typename Cls, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7, typename P8, typename P9, typename P10, typename P11>//11 struct JSCCallback:public IJSCCallback { typedef void(Cls::*F)(P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11); JSCCallback(F func):m_func(func){} virtual JSValueRef call(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception){ JS2CCALL_GET_COBJ; JS2CCALL_GET_PARAMS11; (pThis->*m_func)(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11); resetJsStrBuf(); return JSValueMakeUndefined(ctx); } virtual uint16_t getNumArgs() { return 11; } F m_func; }; template< typename Cls, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7, typename P8, typename P9, typename P10, typename P11, typename P12>//12 struct JSCCallback:public IJSCCallback { typedef void(Cls::*F)(P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12); JSCCallback(F func):m_func(func){} virtual JSValueRef call(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception){ JS2CCALL_GET_COBJ; JS2CCALL_GET_PARAMS12; (pThis->*m_func)(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12); resetJsStrBuf(); return JSValueMakeUndefined(ctx); } virtual uint16_t getNumArgs() { return 12; } F m_func; }; ///////////////////////////////////////////////////////////////////////////////////////////////////////////// #define JS2CCONSTRUCTOR_GET_PARAMS1 \ P1 p1 = __TransferToCpp::ToCpp(arguments[0]); #define JS2CCONSTRUCTOR_GET_PARAMS2 \ P1 p1 = __TransferToCpp::ToCpp(arguments[0]);\ P2 p2 = __TransferToCpp::ToCpp(arguments[1]); #define JS2CCONSTRUCTOR_GET_PARAMS3 \ P1 p1 = __TransferToCpp::ToCpp(arguments[0]);\ P2 p2 = __TransferToCpp::ToCpp(arguments[1]);\ P3 p3 = __TransferToCpp::ToCpp(arguments[2]); template struct JSCConstructor0: public IJSCCallback { virtual JSObjectRef constructor(JSContextRef ctx, JSObjectRef constructor, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception){ return JSCClass::getInstance()->transferObjPtrToJS(new Cls()); } virtual uint16_t getNumArgs() { return 0; } }; template IJSCCallback* regConstructor(){ return new JSCConstructor0(); } template struct JSCConstructor1:public IJSCCallback{ virtual JSObjectRef constructor(JSContextRef ctx, JSObjectRef constructor, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception){ JS2CCONSTRUCTOR_GET_PARAMS1; return JSCClass::getInstance()->transferObjPtrToJS(new Cls(p1)); } virtual uint16_t getNumArgs() { return 1; } }; template IJSCCallback* regConstructor(){ return new JSCConstructor1(); } template struct JSCConstructor2:public IJSCCallback{ virtual JSObjectRef constructor(JSContextRef ctx, JSObjectRef constructor, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception){ JS2CCONSTRUCTOR_GET_PARAMS2; return JSCClass::getInstance()->transferObjPtrToJS(new Cls(p1,p2)); } virtual uint16_t getNumArgs() { return 2; } }; template IJSCCallback* regConstructor(){ return new JSCConstructor2(); } ///////////////////////////////////////////////////////////////////////////////////////////////////////////// struct IJSCFunction { virtual ~IJSCFunction(){} virtual JSValueRef call(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) = 0; virtual uint16_t getNumArgs() = 0; }; template struct JSCFunction: public IJSCFunction { JSCFunction(T func){} virtual JSValueRef call(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception){ assert(false && "JSCFunction::call not implemented"); return nullptr; } virtual uint16_t getNumArgs() { return 0; } }; template//R(void) struct JSCFunction: public IJSCFunction { typedef R(*F)(void); JSCFunction(F func):m_func(func){} virtual JSValueRef call(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception){ JSValueRef ret = ToJSValue((*m_func)()); resetJsStrBuf(); return ret; } virtual uint16_t getNumArgs() { return 0; } F m_func; }; template//R(p1) struct JSCFunction: public IJSCFunction { typedef R(*F)(P1); JSCFunction(F func):m_func(func){} virtual JSValueRef call(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception){ JS2CCALL_GET_PARAMS1; JSValueRef ret = ToJSValue((*m_func)(p1)); resetJsStrBuf(); return ret; } virtual uint16_t getNumArgs() { return 1; } F m_func; }; template//const R(p1) struct JSCFunction:public IJSCFunction { typedef const R(*F)(P1); JSCFunction(F func):m_func(func){} virtual JSValueRef call(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception){ JS2CCALL_GET_PARAMS1; JSValueRef ret = ToJSValue((*m_func)(p1)); resetJsStrBuf(); return ret; } virtual uint16_t getNumArgs() { return 1; } F m_func; }; template//R(p1,p2) struct JSCFunction: public IJSCFunction { typedef R(*F)(P1,P2); JSCFunction(F func):m_func(func){} virtual JSValueRef call(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception){ JS2CCALL_GET_PARAMS2; JSValueRef ret = ToJSValue((*m_func)(p1, p2)); resetJsStrBuf(); return ret; } virtual uint16_t getNumArgs() { return 2; } F m_func; }; template//3 struct JSCFunction: public IJSCFunction { typedef R(*F)(P1, P2, P3); JSCFunction(F func):m_func(func){} virtual JSValueRef call(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception){ JS2CCALL_GET_PARAMS3; JSValueRef ret = ToJSValue((*m_func)(p1, p2, p3)); resetJsStrBuf(); return ret; } virtual uint16_t getNumArgs() { return 3; } F m_func; }; template//4 struct JSCFunction: public IJSCFunction { typedef R(*F)(P1, P2, P3, P4); JSCFunction(F func):m_func(func){} virtual JSValueRef call(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception){ JS2CCALL_GET_PARAMS4; JSValueRef ret = ToJSValue((*m_func)(p1, p2, p3, p4)); resetJsStrBuf(); return ret; } virtual uint16_t getNumArgs() { return 4; } F m_func; }; template//5 struct JSCFunction: public IJSCFunction { typedef R(*F)(P1, P2, P3, P4, P5); JSCFunction(F func):m_func(func){} virtual JSValueRef call(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception){ JS2CCALL_GET_PARAMS5; JSValueRef ret = ToJSValue((*m_func)(p1, p2, p3, p4, p5)); resetJsStrBuf(); return ret; } virtual uint16_t getNumArgs() { return 5; } F m_func; }; template//6 struct JSCFunction: public IJSCFunction { typedef R(*F)(P1, P2, P3, P4, P5, P6); JSCFunction(F func):m_func(func){} virtual JSValueRef call(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception){ JS2CCALL_GET_PARAMS6; JSValueRef ret = ToJSValue((*m_func)(p1, p2, p3, p4, p5, p6)); resetJsStrBuf(); return ret; } virtual uint16_t getNumArgs() { return 6; } F m_func; }; template//7 struct JSCFunction: public IJSCFunction { typedef R(*F)(P1, P2, P3, P4, P5, P6, P7); JSCFunction(F func):m_func(func){} virtual JSValueRef call(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception){ JS2CCALL_GET_PARAMS7; JSValueRef ret = ToJSValue((*m_func)(p1, p2, p3, p4, p5, p6, p7)); resetJsStrBuf(); return ret; } virtual uint16_t getNumArgs() { return 7; } F m_func; }; template//8 struct JSCFunction: public IJSCFunction { typedef R(*F)(P1, P2, P3, P4, P5, P6, P7, P8); JSCFunction(F func):m_func(func){} virtual JSValueRef call(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception){ JS2CCALL_GET_PARAMS8; JSValueRef ret = ToJSValue((*m_func)(p1, p2, p3, p4, p5, p6, p7, p8)); resetJsStrBuf(); return ret; } virtual uint16_t getNumArgs() { return 8; } F m_func; }; template//9 struct JSCFunction: public IJSCFunction { typedef R(*F)(P1, P2, P3, P4, P5, P6, P7, P8, P9); JSCFunction(F func):m_func(func){} virtual JSValueRef call(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception){ JS2CCALL_GET_PARAMS9; JSValueRef ret = ToJSValue((*m_func)(p1, p2, p3, p4, p5, p6, p7, p8, p9)); resetJsStrBuf(); return ret; } virtual uint16_t getNumArgs() { return 9; } F m_func; }; //void template<> //void(void) struct JSCFunction: public IJSCFunction { typedef void(*F)(void); JSCFunction(F func):m_func(func){} virtual JSValueRef call(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception){ (*m_func)(); resetJsStrBuf(); return JSValueMakeUndefined(ctx); } virtual uint16_t getNumArgs() { return 0; } F m_func; }; template struct JSCFunction: public IJSCFunction {//void(p1) typedef void(*F)(P1); JSCFunction(F func):m_func(func){} virtual JSValueRef call(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception){ JS2CCALL_GET_PARAMS1; (*m_func)(p1); resetJsStrBuf(); return JSValueMakeUndefined(ctx); } virtual uint16_t getNumArgs() { return 1; } F m_func; }; template//void(p1,p2) struct JSCFunction: public IJSCFunction { typedef void(*F)(P1, P2); JSCFunction(F func):m_func(func){} virtual JSValueRef call(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception){ JS2CCALL_GET_PARAMS2; (*m_func)(p1, p2); resetJsStrBuf(); return JSValueMakeUndefined(ctx); } virtual uint16_t getNumArgs() { return 2; } F m_func; }; template< typename P1, typename P2, typename P3>//3 struct JSCFunction: public IJSCFunction { typedef void(*F)(P1, P2, P3); JSCFunction(F func):m_func(func){} virtual JSValueRef call(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception){ JS2CCALL_GET_PARAMS3; (*m_func)(p1, p2, p3); resetJsStrBuf(); return JSValueMakeUndefined(ctx); } virtual uint16_t getNumArgs() { return 3; } F m_func; }; template//4 struct JSCFunction: public IJSCFunction { typedef void(*F)(P1, P2, P3, P4); JSCFunction(F func):m_func(func){} virtual JSValueRef call(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception){ JS2CCALL_GET_PARAMS4; (*m_func)(p1, p2, p3, p4); resetJsStrBuf(); return JSValueMakeUndefined(ctx); } virtual uint16_t getNumArgs() { return 4; } F m_func; }; template//5 struct JSCFunction: public IJSCFunction { typedef void(*F)(P1, P2, P3, P4, P5); JSCFunction(F func):m_func(func){} virtual JSValueRef call(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception){ JS2CCALL_GET_PARAMS5; (*m_func)(p1, p2, p3, p4, p5); resetJsStrBuf(); return JSValueMakeUndefined(ctx); } virtual uint16_t getNumArgs() { return 5; } F m_func; }; template//6 struct JSCFunction: public IJSCFunction { typedef void(*F)(P1, P2, P3, P4, P5, P6); JSCFunction(F func):m_func(func){} virtual JSValueRef call(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception){ JS2CCALL_GET_PARAMS6; (*m_func)(p1, p2, p3, p4, p5, p6); resetJsStrBuf(); return JSValueMakeUndefined(ctx); } virtual uint16_t getNumArgs() { return 6; } F m_func; }; template< typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7>//7 struct JSCFunction: public IJSCFunction { typedef void(*F)(P1, P2, P3, P4, P5, P6, P7); JSCFunction(F func):m_func(func){} virtual JSValueRef call(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception){ JS2CCALL_GET_PARAMS7; (*m_func)(p1, p2, p3, p4, p5, p6, p7); resetJsStrBuf(); return JSValueMakeUndefined(ctx); } virtual uint16_t getNumArgs() { return 7; } F m_func; }; template//8 struct JSCFunction: public IJSCFunction { typedef void(*F)(P1, P2, P3, P4, P5, P6, P7, P8); JSCFunction(F func):m_func(func){} virtual JSValueRef call(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception){ JS2CCALL_GET_PARAMS8; (*m_func)(p1, p2, p3, p4, p5, p6, p7, p8); resetJsStrBuf(); return JSValueMakeUndefined(ctx); } virtual uint16_t getNumArgs() { return 8; } F m_func; }; template//9 struct JSCFunction: public IJSCFunction { typedef void(*F)(P1, P2, P3, P4, P5, P6, P7, P8, P9); JSCFunction(F func):m_func(func){} virtual JSValueRef call(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception){ JS2CCALL_GET_PARAMS9; (*m_func)(p1, p2, p3, p4, p5, p6, p7, p8, p9); resetJsStrBuf(); return JSValueMakeUndefined(ctx); } virtual uint16_t getNumArgs() { return 9; } F m_func; }; template//12 struct JSCFunction: public IJSCFunction { typedef void(*F)(P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12); JSCFunction(F func):m_func(func){} virtual JSValueRef call(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception){ JS2CCALL_GET_PARAMS12; (*m_func)(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12); resetJsStrBuf(); return JSValueMakeUndefined(ctx); } virtual uint16_t getNumArgs() { return 12; } F m_func; }; } // namespace __JSCProxy #endif