HISE Logo Forum
    • Categories
    • Register
    • Login

    How to prevent duplicate include?

    Scheduled Pinned Locked Moved Scripting
    12 Posts 3 Posters 443 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.
    • A
      aaronventure @d.healey
      last edited by aaronventure

      @d-healey

      what do you mean? Where else would one put them? I get an error "Duplicate namespace" nonetheless.

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

        @aaronventure said in How to prevent duplicate include?:

        Where else would one put them?

        Ah I thought you meant you were attempting to include them within another namespace.

        @aaronventure said in How to prevent duplicate include?:

        "Duplicate namespace"

        That means you have two namespaces with the same name, so change the name of one of them.

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

        A 1 Reply Last reply Reply Quote 0
        • A
          aaronventure @d.healey
          last edited by

          @d-healey Alright here's an example.

          I have Animation.js which also relies on MathX.js

          I don't want to have t remember that, so if I load in Animation.js after I alreaded included MathX.js, the Animation.js should skip its own include for the MathX,js .

          This can be done with the preprocessor, but the preprocessor constants are global so I can't do the same trick in another script processor.

          The include call does not respect HISEScript's if/then -- I can't declare a HISEScript const inside the include file that I can then check for using if/then.

          6cd452b5-090b-484e-9d05-c70d1b9fbf9a-image.png

          d.healeyD ustkU 2 Replies Last reply Reply Quote 0
          • d.healeyD
            d.healey @aaronventure
            last edited by d.healey

            @aaronventure said in How to prevent duplicate include?:

            Animation.js should skip its own include for the MathX,js .

            This is what I mean by I put all my includes directly in on init not within another script file. That way I have to explicitly state what includes are available, the worst that happens is when I include a file it tells me that it can't find X function/namespace so I have to add another include.

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

            1 Reply Last reply Reply Quote 0
            • ustkU
              ustk @aaronventure
              last edited by

              @aaronventure Haven't tried, but you could start all your namespaces with a variable of the same name, and check isDefined(MyNamespace.MyVar) in dependencies. If not defined just throw a message in the console for which include is required.
              It's far from being automated but at least you get all the required includes at init showing in the console.

              A use of Console.assert might be helpful as well in the include's functions that depend on others includes/namespaces

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

              A 1 Reply Last reply Reply Quote 1
              • A
                aaronventure @ustk
                last edited by

                @ustk yep that's what I'll do, thanks

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

                  @aaronventure I'm seeing a good use case for this in my latest project. I tried @ustk suggestion but it didn't work. Did you find a solution?

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

                  A 1 Reply Last reply Reply Quote 0
                  • A
                    aaronventure @d.healey
                    last edited by

                    @d-healey Yeah, for each namespace, I have a exists constant.

                    Then in the ones that require other namespaces, I have, for example

                    if (MathX.exists == false)
                    	{
                    		Console.print("Controls.js requires MathX.");
                    	}
                    
                    d.healeyD 1 Reply Last reply Reply Quote 1
                    • d.healeyD
                      d.healey @aaronventure
                      last edited by

                      @aaronventure ah I get it now, thanks.

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

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

                        @Christoph-Hart What about adding #pragma once? Or just ignoring duplicate includes - I can't think of a downside to that but maybe there is.

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

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

                        15

                        Online

                        1.8k

                        Users

                        12.1k

                        Topics

                        104.9k

                        Posts