Announcement

Collapse
No announcement yet.

function libraries

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • function libraries

    When I use function libraries, how can those functions in the libraries access (set the values of) the variables defined in the calling scripts? For example, in an EFS script, I have a few variables A, B, C, D, E which need to be initialized. The initialization function is defined in an epslib so that it can be shared by multiple EFS's. However instead of using Array to pass the returned values from initialization function to the main efs, can the initialization function manipulates the variables in the main efs just a function defined in the main efs can access the variables defined outside of any functions in the main efs?

  • #2
    I believe so...

    All I think you have to do is....

    include a POINTER for the variables..

    PHP Code:

    var myLibrary addLibrary ("myefsLib.efsLib");


    function 
    main() {

      
    myLibrary.null;
      
    myLibrary.100.00


    A and B are defined in the Library file. You simply need to include the Pointer ID for the variable.

    I hope this helps.
    Brad Matheny
    eSignal Solution Provider since 2000

    Comment


    • #3
      Doji,

      Maybe I didnot state my question clearly in my previous post. The problem is I have several EFS's, each of which has the same set of variables need to be initialized. So the efs looks like

      /*************************************/
      // indicatorA.efs
      /*************************************/
      var A, B, C, D, E, F;

      function preMain() { }

      function main() {
      if ( getBarState() == BARSTATE_ALLBARS ) {
      // inializing A, B, C, D, E, F here
      }

      // access A, B, C, D, E, F here
      }
      /*******************************************/
      // end of indicatorA.efs
      /*******************************************/


      I want to put the initializing code in an efslib so that if I want to change the initial values of A, B, C, D, E, F, I only need to edit the efslib file instead of editing all the indicatorXXX.efs one by one. It seems the solution you gave is to access the variable in efslib file from the indicator efs instead of the other way. Am I right?

      Comment


      • #4
        well, if all of these variables are STATIC and GLOBAL, then you should be able to call/change them in the efsLib already.

        The issue here is "code order" and how you want to use these variables. If they are declared in the EFS file that loads the Libs, then you should be able to access them within the Lib files..

        Another possible solution is to create a function that initializes them with the EFS file. Declare them as GLOBALS, then call the function to INITIALIZE/RESET them. This function should be able to be called from within the Lib files also.

        B
        Brad Matheny
        eSignal Solution Provider since 2000

        Comment


        • #5
          Doji,

          Thanks for the explanation. It seems loading an efslib is similar to "including" the efslib file in the loading efs so that the functions defined in the efslib can access the global variables (those variables outside of main()) just as those functions defined in the loading efs do. Am I right?

          - Clearpicks

          Comment


          • #6
            Hi clearpicks,

            I am not sure if this will help any further, but a library is declared as a separate object (more of a namespace) in the global scope of each individual efs using this command var myLibrary = addLibrary ("myefsLib.efsLib"); (from Brad's example).

            Any changes made to the library variables from an efs would be unique to the particular efs scope and library instance.

            To change these globally I recommend that you modify the values in the efsLibrary, save those changes, then re-load each efs to load those new library variables.

            Hope this helps.

            Comment


            • #7
              yes, very similar to an "include". The Globals declared in your EFS are GLOBAL (available within the efsLib file as well). The variables declared within your efsLib file are local to that efsLib file, but can be accessed in your efs file by including a POINTER...

              if (myefsLib.variable_A == 1) {
              .. do something
              }

              This is an example of "pulling" an efsLib variable and checking it's value from your efs..

              If you were to try this within the efsLib, it should look like this (less the pointer)

              if (variable_A == 1) {
              .. do something
              }
              Brad Matheny
              eSignal Solution Provider since 2000

              Comment

              Working...
              X