Skip to main content
Known Participant
July 21, 2014
Question

IScriptRunner with Return Values

  • July 21, 2014
  • 1 reply
  • 840 views

Hello all,

I am trying to run a Javascript script from within my plugin written in C++. I am using CS6. I saw in the forum, that older interfaces do have a ScriptData return value but the version in CS6 only takes a script and parameters.

Is there a way to run a script and retrieve the data again inside the plugin?

Thank you.

Best regards,

Reinhard

This topic has been closed for replies.

1 reply

Bartek_Kropaczewski
Inspiring
July 21, 2014

Hi

You can use IScriptUtils. See that code below.

        InterfacePtr<IScriptManager> scriptManager(Utils<IScriptUtils>()->QueryScriptManager(kJavaScriptMgrBoss));

        if (!scriptManager)

            break;

        InterfacePtr<IScriptEngine> scriptEngine(scriptManager->QueryDefaultEngine());

        if (!scriptEngine)

            break;

        InterfacePtr<IScriptRunner> scriptRunner(scriptEngine, UseDefaultIID());

        PMString theReturnString;

        PMString theErrorString;

        PMString theScriptString("\nmain();\nfunction main()\n{\n\treturn \"Hello World\";\n\n}\n");

        ScriptRecordData args;

        ScriptData sScript(theScriptString);

        ScriptData sResultData;

       

        ErrorCode result = Utils<IScriptUtils>()->DispatchScriptRunner(scriptRunner, sScript, args, sResultData, theErrorString, kFalse);

        sResultData.GetPMString(theReturnString);

Regards

Bartek

Known Participant
July 21, 2014

Thank you very much. This looks very promising.

However something seems to go wrong. When an object of type ScriptRecordData is used I get a linker error and I am lost again.

I hope once for for your help.

NB: The Linker error only appears when the destructor is invoked. This is really weird..

Thank you!

Reinhard

Bartek_Kropaczewski
Inspiring
July 21, 2014

I'm afraid I don't know what kind of destructor you're calling . Do you have any details regarding  that linker error ?