Passing multiple parameters from javascript to C++ using UXP hybrid plug-ins

I’ve had a hard time calling a function that takes multiple parameters going from JavaScript to C++. For example, I tried working with the sample plug-in, trying to modify the “MyEcho” to accept two parameters. This is the sample C++ code for extracting the first parameter:

        // Allocate space for the first argument
        addon_value arg1;
        size_t argc = 1;
        Check(UxpAddonApis.uxp_addon_get_cb_info(env, info, &argc, &arg1, nullptr, nullptr));

        // Convert the first argument to a value that can be retained past the
        // return from this function. This is needed if you want to pass arguments
        // to an asynchronous/deferred task handler
        Value stdValue(env, arg1);

uxp_addon_get_cb_info isn’t well documented, but I was hoping incrementing argc would point it at the second parameter. That doesn’t work, however - argc always comes out with a value of 2, and it always returns the first parameter, regardless of what argc is set to.

Any insight here?

Thanks!

Lawrence

You need to set argc (argument count) to the number of parameters. In your case 2. You can tell from the signature of uxp_addon_get_cb_info that it requires a pointer, hence you pass the address to argc (same as in the sample code).

Take a look at the function declaration in uxpAddonShared.h:
addon_status (*uxp_addon_get_cb_info)( addon_env env, addon_callback_info cbinfo, size_t* argc, addon_value* argv, addon_value* this_arg, void** data);

For the actual arguments argv it asks for a pointer to an args-vector, i.e. an array of arguments. In the case of just one argument you just pass the address to arg1 (as done in the sample code), but in case of more arguments you will have to allocate an array of addon_value and pass the address to that.

1 Like

Thanks for those pointers (and pardon the pun). That’s all I needed.

Best,

Lawrence