1231 – replaceFileContentWithData missing

Home Forums General News and releases 1231 – replaceFileContentWithData missing

Tagged: 

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #5852
    Hecticcc
    Participant
      • Topics: 25
      • Replies: 160
      • Total: 185
      • ★★

      I am trying to save some data to disk using an example from elsewhere on the forum, and when Lua wants to call replaceFileContentWithData it returns

      <code>attempt to call ‘replaceFileContentWithData’ (a nil value)

      </code>

      I tried using the new what() on the file object and the functions returned do not list replaceFileContentWithData:

      <code>

      __init:    function
      getFileName:    function
      hasFileExtension:    function
      getFileExtension:    function
      isOnHardDisk:    function
      hasWriteAccess:    function
      getNonexistentChildFile:    function
      replaceWithData:    function
      getRelativePathFrom:    function
      getNonexistentSibling:    function
      setReadOnly:    function
      getVolumeTotalSize:    function
      getSize:    function
      getSiblingFile:    function
      getCreationTime:    function
      hashCode64:    function
      hashCode:    function
      getVolumeLabel:    function
      getParentDirectory:    function
      moveToTrash:    function
      exists:    function
      findChildFiles:    function
      loadFileAsString:    function
      getFileNameWithoutExtension:    function
      withFileExtension:    function
      create:    function
      getNumberOfChildFiles:    function
      getVersion:    function
      hasIdenticalContentTo:    function
      setLastAccessTime:    function
      deleteRecursively:    function
      replaceWithText:    function
      isOnRemovableDrive:    function
      createDirectory:    function
      getLinkedTarget:    function
      getVolumeSerialNumber:    function
      isAChildOf:    function
      getChildFile:    function
      isDirectory:    function
      deleteFile:    function
      getLastModificationTime:    function
      getLastAccessTime:    function
      isHidden:    function
      setCreationTime:    function
      moveFileTo:    function
      copyFileTo:    function
      existsAsFile:    function
      getFullPathName:    function
      startAsProcess:    function
      setAsCurrentWorkingDirectory:    function
      loadFileAsData:    function
      isOnCDRomDrive:    function
      setLastModificationTime:    function
      containsSubDirectories:    function
      getBytesFreeOnVolume:    function
      revealToUser:    function
      appendData:    function
      appendText:    function

      </code>

      #5853
      dasfaker
      Keymaster
        • Topics: 80
        • Replies: 793
        • Total: 873
        • ★★★

        Now it’s replaceWithData

        #5854
        Hecticcc
        Participant
          • Topics: 25
          • Replies: 160
          • Total: 185
          • ★★

          lol i just noticed 🙂

          But i am having trouble with it, i cannot seem to be bale to save the contents of a memoryblock, if it try i get “no matching overload found”

          Example:
          In a script:

          data = somevalue
          mb = CtrlrLuaMemoryBlock
          mb:append(data)
          saveToFile(mb)

          in the saveToFile script:

          function saveToFile(dataToSave)

          -- By default the dialog window will ask for confirmation on overwrites, so we don't need to check
          -- You can replace the File("").getSpecialLocation(File.userDesktopDirectory) with some other file location
          -- that can be remembered across calls so that you hint the user his last browsed dir or some other location

          --x = string.format(dataToSave)

          file = utils.saveFileWindow ("Save file", File(""), "*.emu", true)

          if not file:hasFileExtension(String ("emu")) then
          -- this is stupid the File() should not be necessary but luabind does not handle type conversions well

          file = File (file:withFileExtension(String ("emu")))
          end

          if file:hasWriteAccess() then
          -- We can write to that location

          file:replaceWithData(mb)
          end
          debug (what(file))
          end

          If i do not use a memoryblock and save the data as textstring it works…

          #5855
          dasfaker
          Keymaster
            • Topics: 80
            • Replies: 793
            • Total: 873
            • ★★★

            Try this:

            data1 = 10
            data2 = 20
            mb = MemoryBlock()
            mb:insert(mb,data1)
            mb:insert(mb,data2)
            console (mb:toHexString(1))
            if configFile:existsAsFile() then -- your file here
            configFile:replaceWithData(mb)
            end

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

              Check what(mb) i can’t see it initialized in the saveToFile() function

              #5860
              Hecticcc
              Participant
                • Topics: 25
                • Replies: 160
                • Total: 185
                • ★★

                Thanks guys, gonna try it later today when my son is taking his nap 🙂
                Will update with results.

                #5868
                Hecticcc
                Participant
                  • Topics: 25
                  • Replies: 160
                  • Total: 185
                  • ★★

                  Got it working, thanks guys 🙂

                  I was declaring the memoryblock in the script that holds the values to be saved, and tried to pass it as an argument to saveToFile instead of making it in the saveToFile script itself.
                  I did have to do a little trickery to get it working as it looks like  passing userdata as argument for a function is not possible.

                  I want to save the result of a midi:getRange() but if i try i get errors. Worked around by making it a table and then it works as expected.

                  Now it looks like this:

                  originating script:

                  l = midi:getSize()

                  if  l == 255 then --programdump
                  -- make table from midimessage
                  t = {}
                  for i =1, l-1 do -- -1  remove header
                  byte = midi:getLuaData():getByte(i)
                  table.insert(t,i,byte)
                  end

                  saveToFile(t)
                  end

                  In saveToFile:

                  function saveToFile(data)

                  mb = MemoryBlock()
                  mb:createFromTable(data)
                  file = utils.saveFileWindow ("Save file", File("test"), "*.emu", true)

                  if not file:hasFileExtension(String ("emu")) then
                  -- this is stupid the File() should not be necessary but luabind does not handle type conversions well

                  file = File (file:withFileExtension(String ("emu")))
                  end

                  if file:hasWriteAccess() then
                  -- We can write to that location
                  file:replaceWithData(mb)
                  end
                  end

                  • This reply was modified 11 years, 3 months ago by Hecticcc. Reason: tags
                  • This reply was modified 11 years, 3 months ago by Hecticcc. Reason: code tags
                  • This reply was modified 11 years, 3 months ago by Hecticcc. Reason: trying to edit tags for code to be correct
                  • This reply was modified 11 years, 3 months ago by Hecticcc.
                  #5873
                  atom
                  Keymaster
                    • Topics: 159
                    • Replies: 2945
                    • Total: 3104
                    • ★★★★★

                    I did have to do a little trickery to get it working as it looks like  passing userdata as argument for a function is not possible.

                    That’s impossible passing ANYTHING as a parameter to any function is valid and will work.

                    #5874
                    Hecticcc
                    Participant
                      • Topics: 25
                      • Replies: 160
                      • Total: 185
                      • ★★

                      If i try this in saveToFile

                      mb=MemoryBlock()
                      mb:append(data) -- getrange result passed as parameter
                      <\code>

                      It gives an error. Same if i try mb:insert(mb,data)

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