HISE Logo Forum
    • Categories
    • Register
    • Login

    Local variables for namespaces

    Scheduled Pinned Locked Moved Scripting
    namespacelocalvariable
    8 Posts 4 Posters 353 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • d.healeyD
      d.healey
      last edited by d.healey

      As I was just testing something with local variables inside inline functions it occurred to me that we don't have the equivalent for namespaces and have to rely on var or reg.

      var is no good because of the scope:

      namespace MyNamespace
      {
          var aVariable = 10;
      }
      
      Console.print(aVariable); // 10
      

      And reg isn't ideal because of the limit of 32 and the performance decrease as you use more of them.

      @Christoph-Hart Could we get local variables for namespaces?

      Libre Wave - Freedom respecting instruments and effects
      My Patreon - HISE tutorials
      YouTube Channel - Public HISE tutorials

      LindonL 1 Reply Last reply Reply Quote 1
      • LindonL
        Lindon @d.healey
        last edited by

        @d-healey wiered - I'm using locals all over my namespaces:

        inline function writeExpansion(expansionName)
        {
        
            // NEW STYLE
            local mySaveData;
            local myDataName; 
            for (e in expSet)
            {
                if (e.EName == expansionName)
                {
                   myDataName = e.EName.replace(" ", "");
                   Engine.dumpAsJSON(e, "../" + myDataName + "_MetaData.json"); 
                   Console.print("writing:" + "../" + myDataName + "_MetaData.json"); 
                }
            }
        }
        

        HISE Development for hire.
        www.channelrobot.com

        1 Reply Last reply Reply Quote 0
        • d.healeyD
          d.healey
          last edited by d.healey

          That's inside an inline function

          Libre Wave - Freedom respecting instruments and effects
          My Patreon - HISE tutorials
          YouTube Channel - Public HISE tutorials

          ustkU LindonL 2 Replies Last reply Reply Quote 1
          • ustkU
            ustk @d.healey
            last edited by

            @d-healey That's strange because const var is scoped to the namespace, but not var...

            Can't help pressing F5 in the forum...

            d.healeyD 1 Reply Last reply Reply Quote 0
            • d.healeyD
              d.healey @ustk
              last edited by d.healey

              @ustk const is a different beast, because they can't be changed the precompiler can just replace them with fixed values, and scope isn't an issue. I've stopped using const var now and always just use const instead, since Christoph said they are both the same.

              Libre Wave - Freedom respecting instruments and effects
              My Patreon - HISE tutorials
              YouTube Channel - Public HISE tutorials

              ustkU 1 Reply Last reply Reply Quote 1
              • ustkU
                ustk @d.healey
                last edited by

                @d-healey That is 4 characters saved, seeing how fast I type I should definitely switch to this advanced coding technique 😁

                Can't help pressing F5 in the forum...

                1 Reply Last reply Reply Quote 0
                • LindonL
                  Lindon @d.healey
                  last edited by

                  @d-healey said in Local variables for namespaces:

                  That's inside an inline function

                  true - got me there officer, I will come quietly...

                  HISE Development for hire.
                  www.channelrobot.com

                  1 Reply Last reply Reply Quote 1
                  • Christoph HartC
                    Christoph Hart
                    last edited by

                    Could we get local variables for namespaces?

                    I would say that if you exceed 32 variables in a single namespace it might be better to break down the code into multiple modules for clarity anyway. Also I'd like to keep local variables inside inline functions to not confuse people more.

                    1 Reply Last reply Reply Quote 1
                    • First post
                      Last post

                    37

                    Online

                    1.7k

                    Users

                    11.7k

                    Topics

                    102.2k

                    Posts