4 Replies Latest reply on Jul 22, 2011 3:30 AM by Marc Autret

    global variables

    scriptworker

      Is there a way to share global variables in jsxbin files?

      #include does not work with binary files, so I use app.doScript.

      But this does not include the vars from the script that is called with doScript.

       

      Any Ideas?

       

      Kind regards,
      Michel

        • 1. Re: global variables
          Marc Autret Level 4

          Hi Michel,

           

          > Is there a way to share global variables in jsxbin files?

           

          I'm afraid I don't get your point. Let's recap:

           

          1) The jsxbin format is nothing but a way to encrypt JS code.

           

          2) Indeed, you cannot use an #include directive on jsxbin files.

           

          3) There are several ways to execute encrypted codes though:

               a) app.doScript( File('my/path/to/file.jsxbin') );

               b) $.evalFile( File('my/path/to/file.jsxbin') );

               c) app.doScript( <jsxbin_string> );

               d) eval( <jsxbin_string> );

           

           

          OK. Now suppose that inc01.jsxbin encodes this declaration:

           

          var a = "foo", b = "bar";
          

           

          and that inc02.jsxbin encodes this statement:

           

          alert( a + b );
          

           

          From there, the following script should perfectly work:

           

          /* Main.jsx */
          
          app.doScript( File('my/path/to/inc01.jsxbin') );
          app.doScript( File('my/path/to/inc02.jsxbin') );
          // => 'foobar'
          

           

          This proves that the vars a and b are actually 'shared' between inc01.jsxbin and inc02.jsxbin. Don't you get that result?

           

          (Apart from this, note that there is usually no reason to encrypt individual jsxbin files before producing the final script. I find it more convenient to benefit from jsx—clear code—inclusion and to finally export the main script into a single jsxbin.)

           

          @+

          Marc

          • 2. Re: global variables
            scriptworker Level 1

            This is strange. It did not work in my case.

            I'll try it again. Maybe I did something wrong.

             

            Main is also a jsxbin in my case, but I don't

            think this is of any influence.

             

            Kind regards,

            Michel

            • 3. Re: global variables
              scriptworker Level 1

              The problem seems to be that the script is running in a targetengine

              and that global vars are not shared. Any solution for this.

               

              Michel

              • 4. Re: global variables
                Marc Autret Level 4
                The problem seems to be that the script is running in a targetengine (...)

                 

                Ha-ha! This changes many things!

                 

                There are some issues in using  jsxbin with targetengine:

                (a) Each persistent engine runs within its own namespace,

                (b) jsxbin cannot load by itself a persistent engine.

                Take a look here: http://www.indiscripts.com/post/2010/04/binary-javascript-embedment-cs4-cs5

                 

                @+

                Marc