Rockbox.org home
Downloads
Release release
Dev builds dev builds
Extras extras
themes themes
Documentation
Manual manual
Wiki wiki
Device Status device status
Support
Forums forums
Mailing lists mailing lists
IRC IRC
Development
Bugs bugs
Patches patches
Dev Guide dev guide
Search



Donate

Rockbox Technical Forums


Login with username, password and session length
Home Help Search Staff List Login Register
News:

Thank You for your continued support and contributions!

+  Rockbox Technical Forums
|-+  Support and General Use
| |-+  Plugins/Viewers
| | |-+  Directory operations in Lua script?
« previous next »
  • Print
Pages: [1]

Author Topic: Directory operations in Lua script?  (Read 5568 times)

Offline Crend King

  • Member
  • *
  • Posts: 17
Directory operations in Lua script?
« on: July 17, 2009, 12:36:26 AM »
Hello. I would like to write a little Lua script to do some file and directory operations in Rockbox 3.3. Although the plugin.h contains functions like mkdir(), rmdir() and dir_exists(), I do not see them in the Lua rb table. rb.remove() on a directory returns -1. The only function I found successful on directory is rename(). So I guess the directory operations are not supported yet, right?

Or is there up-to-date Lua reference documentation for Rockbox? I found one at http://mcuelenaere.alwaysdata.net/rockbox_api/, but there is no file/directory functions listed. Although they are listed when I switch to show undocumented functions, I cannot tell which ones are supported in the current Rockbox. It seems this site is not up-to-date.

Thanks!
« Last Edit: July 18, 2009, 03:12:56 PM by CrendKing »
Logged

Offline Grahack

  • Member
  • *
  • Posts: 13
Re: Directory operations in Lua script?
« Reply #1 on: July 19, 2009, 03:29:56 PM »
dir_exists() is in the rb table. I don't know why rmdir and mkdir don't appear here.
From my personal investigations, rb.remove(path) deletes files and *empty* dirs.
To know what is and what is not available, I wrote a small script available here.
Logged

Offline Crend King

  • Member
  • *
  • Posts: 17
Re: Directory operations in Lua script?
« Reply #2 on: July 19, 2009, 06:01:56 PM »
Thanks for reply. Unfortunately in my Rockbox 3.3 copy, rb.remove() does not remove empty directories, but only files. Also, dir_exists() does not exist in my copy. Which version do you have?

I know how to iterate and display the members in rb table. I'm more interested in the script from your link that dump the members to a rb.txt. But when I run it in the UiSimulator, it reports error: /test.lua:20: attempt to index global 'io' (a nil value). Instead, I slightly modified the code to
Code: [Select]
rb_obj = {}
for k, v in pairs(rb) do
    local the_type = type(v)..'s'
    if not rb_obj[the_type] then
        rb_obj[the_type] = {}
        end
    table.insert(rb_obj[the_type], k)
    end

local list = {}
for rb_type, rb_table in pairs(rb_obj) do
    table.insert(list, string.format('* %s *', rb_type))
    table.sort(rb_table)
    for _, v in ipairs(rb_table) do
        table.insert(list, v)
        end
    -- jump a line
    table.insert(list, '')
    end
local file = rb.open('/rb.txt', rb.TRUNC or rb.O_WRONLY)
rb.write(file, table.concat(list, '\n'))
rb.close(file)
and successfully dumped out the members. The attachment is the rb.txt. I wonder besides rb and string, is there any other global objects available in Rockbox Lua?

Frankly what I want is to remove the directories generated by the Apple iPod OS, which is loaded when I connect my iPod to the computer and forget to unlock to switch. It is easy to easy to write Windows batch file to accomplish this, but it requires another connection with computer. It would be much more convenient to run a program or script natively in Rockbox to do this, and Lua comes to my screen as a simpler solution. Thus, I actually do not care about dir_exists(), but more interested in dir_remove() or rmdir().
* rb.txt (0.94 kB - downloaded 155 times.)
« Last Edit: July 20, 2009, 02:59:53 AM by CrendKing »
Logged

Offline Grahack

  • Member
  • *
  • Posts: 13
Re: Directory operations in Lua script?
« Reply #3 on: July 20, 2009, 03:39:49 AM »
For all this kind of work: test, fix, test, fix... the only version that is worth having is the current build: http://build.rockbox.org/
The io table was written after the 3.3 release.
Now if you want to delete a non empty directory, maybe you need a recursive function that you need to write from scratch. Or maybe there is already something in the C Rockbox code for this that I'm not aware of.
Logged

Offline safetydan

  • Developer
  • Member
  • *
  • Posts: 248
Re: Directory operations in Lua script?
« Reply #4 on: July 20, 2009, 04:41:32 AM »
Not that I'd want discourage use of the Lua plugin, because it would be great to see some real world usage, but there's already a plugin in Rockbox that will do what you want. You can configure the Disk Tidy plugin to delete additional files when it runs.
Logged

Offline Crend King

  • Member
  • *
  • Posts: 17
Re: Directory operations in Lua script?
« Reply #5 on: July 20, 2009, 03:48:59 PM »
Nice to hear that. I will give a try tonight after work.

No matter what, better script support is not a bad idea, since you only need a notepad to write program. Debugging script code is many times easier than native C. IO performance shortage in script languages should not be a big problem in Rockbox use case. I'm personally a Python fan, and do not resist to learn new things.
Logged

Offline safetydan

  • Developer
  • Member
  • *
  • Posts: 248
Re: Directory operations in Lua script?
« Reply #6 on: July 21, 2009, 02:15:40 AM »
I agree that the Lua plugin should be given as much functionality as possible. All the better to make the simple things easy and the hard things possible.

Do note however that it is under constant development. There's been quite a bit of development since 3.3 and it's worth checking out a current build before doing any Lua work.
Logged

Offline Crend King

  • Member
  • *
  • Posts: 17
Re: Directory operations in Lua script?
« Reply #7 on: July 23, 2009, 09:12:53 PM »
I would like to upgrade my Rockbox to the latest SVN version, but unfortunately these versions use Rockbox USB stack by default, which does not charge battery for iPod currently.
Logged

Offline Grahack

  • Member
  • *
  • Posts: 13
Re: Directory operations in Lua script?
« Reply #8 on: July 24, 2009, 03:54:27 AM »
??

The battery of my iPod charges with current builds. Maybe you could start another thread about this.
Logged

Offline torne

  • Developer
  • Member
  • *
  • Posts: 994
  • arf arf
Re: Directory operations in Lua script?
« Reply #9 on: July 24, 2009, 05:49:23 AM »
Currently many iPod models charge very slowly or not at all, or even continue to discharge, from USB connections. This is a known bug which is being worked on. (FS#8802)

This doesn't stop you from upgrading to the latest version, though: you can manually reboot to the original firmware for USB connections if you need to..
Logged
some kind of ARM guy. ipodvideo/gigabeat-s/h120/clipv2. to save time let's assume i know everything.

Offline Crend King

  • Member
  • *
  • Posts: 17
Re: Directory operations in Lua script?
« Reply #10 on: July 27, 2009, 02:25:21 AM »
I know. For my iPod Video, it is SELECT+PLAY. But because of the "very low battery" mode, it is difficult to catch the right time to press the combination.
Logged

Offline Chronon

  • Rockbox Expert
  • Member
  • *
  • Posts: 4379
Re: Directory operations in Lua script?
« Reply #11 on: July 27, 2009, 04:38:10 AM »
That is the key combination for Disk Mode.  If you're having trouble with timing why not follow the instructions for dual booting given in the manual?
Logged
Sansa e280, Gigabeat F40, Gigabeat S60, Sansa Clip+, iPod Mini 2g

  • Print
Pages: [1]
« previous next »
+  Rockbox Technical Forums
|-+  Support and General Use
| |-+  Plugins/Viewers
| | |-+  Directory operations in Lua script?
 

  • SMF 2.0.17 | SMF © 2019, Simple Machines
  • Rockbox Privacy Policy
  • XHTML
  • RSS
  • WAP2

Page created in 0.091 seconds with 14 queries.