这个只说简单的参数。
static bool js_call_function(const NPObject* npobj, const NPVariand* args, const unint32_t argCount, NPVariant* result) { ... //取值 //NPVARIANT_TO_BOOLEAN(args[0]); //NPVARIANT_TO_INT32( args[0]); //NPVARIANT_TO_DOUBLE( args[0]); NPString str = NPVARIANT_TO_STRING(args[0]); char* ca = (char*)malloc(str.UTF8Length+1); memset(ca, 0, str.UTF8Length+1); strncpy(ca, str.UTF8Characters, str.UTF8Length); ... //BOOLEAN_TO_NPVARIANT(result); // INT32_TO_NPVARIANT(result); // DOUBLE_TO_NPVARIANT(result); //返回值 char* text = "quantum7"; STRINGN_TO_NPVARIANT(text, strlen(text), *result); }
对于NPVARIANT_TO_OBJECT()/OBJECT_TO_NPVARIANT(),参考: