Adding new C++ class to Ctrlr and exposing through Lua

Home Forums General Programming Adding new C++ class to Ctrlr and exposing through Lua

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

      Hi Atom,

      Is there any way to add a new C++ class to Ctrlr and make it accessible from Lua ?

      I have tried adding a new class in \Source\Lua\JuceClasses called LTest which is similar to LColour .

      Here is Source\Lua\JuceClasses\LTest.h :

      #ifndef __L_TEST__
      #define __L_TEST__

      #include “CtrlrLuaManager.h”

      class LTest
      {
      public:
      LTest(int i) {}
      int getValue() const { return 5; }

      static void wrapForLua (lua_State *L);

      };

      #endif

      ————————-

      Here is Source\Lua\JuceClasses\LTest.cpp,

      #include “stdafx.h”
      #include “LTest.h”

      void LTest::wrapForLua (lua_State *L)
      {
      using namespace luabind;

      module(L)
      [
      class_(“Test”)
      .def(constructor())
      .def(“getValue”, &LTest::getValue)
      ];
      }

      I am not trying to wrap a JUCE class, I am simply exposing a simple function from LTest itself.

      But I get a linker error:

      error LNK2019: unresolved external symbol “public: static void __cdecl LTest::wrapForLua(struct lua_State *)” (?wrapForLua@LTest@@SAXPAUlua_State@@@Z) referenced in function “public: void __thiscall CtrlrLuaManager::wrapJuceClasses(struct lua_State *)” (?wrapJuceClasses@CtrlrLuaManager@@QAEXPAUlua_State@@@Z) P:\p4\anandy_anandy-lt_1775\Import\VSS\AudioTools\Src\Prototypes\AuVidPanels\Builds\Generated\Windows\VST\CtrlrWrap.obj

      Using Visual Studio 2010.

      #28453
      atom
      Keymaster
        • Topics: 159
        • Replies: 2945
        • Total: 3104
        • ★★★★★

        You are missing all the template parameters in the wrapForLua() method constructor<>()
        and the class_<>() you need to pass the correct types for luabind to know what’s it binding. You don’t need to call your class LTest if you are going to bind it as Test just call it Test in C++ and in Lua (i use the L prefix so i can define my own classes and distinguish between JUCE and mine implementations)

        #28456
        synth
        Participant
          • Topics: 13
          • Replies: 35
          • Total: 48

          That was a parsing error in the forum. Here are the files again in code tags:

          cpp:

          
          #include "stdafx.h"
          #include "Test.h"
          
          void Test::wrapForLua (lua_State *L)
          {
              using namespace luabind;
          
              module(L)
              [
                  class_<Test>("Test")
                      .def(constructor<uint32>())
                      .def("getValue", &getValue)
              ];
          }
          

          Header:

          #ifndef __TEST__
          #define __TEST__
          
          #include "CtrlrLuaManager.h"
          
          class Test
          {
              public:
                  Test(int i) {}
                  int getValue() const { return 5; }
          
                  static void wrapForLua (lua_State *L);
          
            
          };
          
          #endif

          The template parameters are there, but I still get the error. Just try dropping them in Source/Lua/JUCEClasses , you will see it.

          • This reply was modified 9 years, 7 months ago by synth.
          • This reply was modified 9 years, 7 months ago by synth.
          • This reply was modified 9 years, 7 months ago by synth.
          #28469
          synth
          Participant
            • Topics: 13
            • Replies: 35
            • Total: 48

            ok its working now. Some weird linking error from the VST project.

          Viewing 4 posts - 1 through 4 (of 4 total)
          • The forum ‘Programming’ is closed to new topics and replies.
          There is currently 0 users and 153 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