how to write a right Lua script (in general)

Home Forums General Programming how to write a right Lua script (in general)

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #6283
    SWB
    Participant
      • Topics: 35
      • Replies: 157
      • Total: 192
      • ★★

      I wanted to write a Lua script to open a file from a panel, so I turned to the documentation and found CtrlrLuaUtils > openFileWindow(). Just what I needed, I thought. I even found out how to format the necessary parameters (4 in this case). But then I was stuck. I tried “panel: CtrlrLuaUtils():openFileWindow (“Open File”, File(“”),”*.*”,true) and this compiled OK, but gave  ‘a nil value’ error and the method was disabled. Then I looked further on this forum and found this thread: “Home › Forums › General › Programming › saving/loading data to a file” and this helped me to write the right script format, being file = utils.openFileWindow(….. etc. My question now is where can I find that one has to put (in this case) specifically ‘utils’ with a dot before ‘openFileWindow’ or more in general how to ‘compose’ the right sequence of ‘statements’ using the right prefixes or suffixes?

      #6323
      SWB
      Participant
        • Topics: 35
        • Replies: 157
        • Total: 192
        • ★★

        Maybe my question is not clear. So let me rephrase the question 😉 Is the syntax of Lua for Ctrlr documented or is ‘utils.’ an exception?

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

          It’s not, it used to be but ever since i moved to JUCE classes (not my own ones), all the documentation is on the JUCE website (for the classes), http://www.rawmaterialsoftware.com/juce/api/annotated.html but there are execptions from this rule and that’s a bigger problem.

          The list of currently supported classes are always visible as files: https://sourceforge.net/p/ctrlrv4/code/1284/tree/nightly/Source/Lua/JuceClasses/ if a class name is not here, it’s not bound to Ctrlr yet (or never will be), inside the .cpp file of the file there is a list of methods that are available in Ctrlr.

          In LUA itself when you run Ctrlr, execute a function in the LUA Console

          how()
          

          to see all the available classes and if you want information about a list of method for an object, run (for example, you can do that for any already existing variable in LUA)

          mb = MemoryBlock()
          debug (what(mb))
          
          #6328
          SWB
          Participant
            • Topics: 35
            • Replies: 157
            • Total: 192
            • ★★

            Thanks for your reply, but sorry those links didn’t lead to an answer and maybe you over estimate the intelligence of my questions ;-). I’m just looking for information on using the right syntax for writing Lua scripts in/for Ctrlr. For example (again) the ‘convention’ for writing ‘utils.’ instead of  ‘panel: CtrlrLuaUtils: etc.’  (or something similar) I did find in this case by searching the forum. If the information hadn’t been on this forum I guess I never had found the answer… Knowing where to look for these things may save me (and others?) a lot of time.

            #6329
            atom
            Keymaster
              • Topics: 159
              • Replies: 2945
              • Total: 3104
              • ★★★★★
              #6330
              SWB
              Participant
                • Topics: 35
                • Replies: 157
                • Total: 192
                • ★★

                Thanks again. I will study this documentation and hopefully it gives me a better understanding of Lua in Ctrlr!

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

                  As for the language itself LUA, there is a nice manual: http://www.lua.org/manual/5.1/ with examples and stuff.

                  #6333
                  SWB
                  Participant
                    • Topics: 35
                    • Replies: 157
                    • Total: 192
                    • ★★

                    Yeah, I did use it. I have also ‘Programming in Lua’ by Roberto Ierusalimschy and ‘Beginning Lua Programming’ by Kurt Jung & Aaron Brown. So I start understanding Lua in general, but as always the devil is in the details… BTW (and sincerely not to offend you) but the authors of Lua like you to write Lua and not LUA, because the name refers to Lua meaning ‘moon’  and not to an acronym or so (http://www.lua.org/about.html).

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

                      heh allright 🙂 i didn’t get that deep into what it means, i have no idea why is C++ called that either but i’ll remember 🙂

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