Creating an instance of a class just once

Home Forums General Programming Creating an instance of a class just once

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #29239
    synth
    Participant
      • Topics: 13
      • Replies: 35
      • Total: 48

      I have this C++ class MakeMeOnce. I have exposed it to lua in Ctrlr and I can call functions on it and everything is fine.

      To call its functions I need to create an instance of it as nothing is declared static in it. I create this instance in the “panel has finished loading method”.

      The problem with this is that if I open the panel again then an instance gets created again because the same method executes in the context of this new panel.

      Is there any global method which gets called just once when Ctrlr starts and never again. I could create my instance there and the object would be visible in the Lua State for all panels.

      I am not sure how feasible this is currently as each panel seems to have its own lua state.

      How would you have managed creating a single instance of a C++ class ? This single instance should be visible in all lua panels.

      • This topic was modified 9 years, 7 months ago by synth.
      #29245
      atom
      Keymaster
        • Topics: 159
        • Replies: 2945
        • Total: 3104
        • ★★★★★

        Panels do not share any memory or any other resources, otherwise this would be a mess i can’t handle. You can look at singletons if you wish to have a single instance of a class.

      Viewing 2 posts - 1 through 2 (of 2 total)
      • The forum ‘Programming’ is closed to new topics and replies.
      There is currently 0 users and 119 guests online
      No users are currently active
      Forum Statistics
      Threads: 2,495, Posts: 17,374, Members: 77,605
      Most users ever online was 12 on January 22, 2019 3:47 pm
      Ctrlr