notes about file io

@Simeon mentioned that io.* was enabled (is that in the beta only? I’m setting category to beta just in case) - so I poked it. Random notes.

if I do


Then look - I’ve created a file named “test” in /var/tmp (absolute path). As a test, I hit other files (/var/www/index.html, yes I run apache on my ipad, who doesn’t???), and assuming the mobile user has permission - you’re not sandboxed, at all (or, well, you’re sandboxed to /var, which has most things). As much as I enjoy the concept of UNLIMITED POWER - this is a bit scary, isn’t it? It is to me. I suspect that’s the default state for an app - but it probably should not be for a Codea project.

FWIW, if you’re willing to look up your app id hash (or whatever it’s called), you can dig your way back into Codea and get to your own projects, but it’s ugly (yay for a jailbroken ipad and ifile). os.getenv will help there, but I think better may be to chdir() us to Documents/Our-Project-name.codea as part of initialization - people who want out can “…” or use an absolute path or just not get out…

By the way, the editor still wraps long lines funky.

I would like to add a generic readData / saveData API that follows the Codea API design. Complete with visual file-pickers for any data type.

I’ve re-written the editor so that it handles wrapping properly. But it’s not going in Codea just yet — we have so many new features on various branches that we need to start pulling them back into the next major version.

This is very interesting. I’ve been playing around with text input and would really like some way to get a text file from a Codea app somewhere where I can read it in another app. Sounds like this might let me save it directly into its document directory! Is that right?

I suspect that wouldn’t last long once Apple spotted it.

However, if you do fix this, can we get clipboard access? Copy-to and Copy-from clipboard? My alternate scheme is to save the text as a dummy .lua file then use the export-to-clipboard from the main screen: bit of a hack, really. Upload to Dropbox would be alright, but would require an internet connection to transfer to another app.

My understanding - and TLL can almost certainly say for sure - is that programmatic access to the clipboard is strictly forbidden - the only way to get data to/from it is via direct user manipulation.

But yes - at least for now, cwd is “/var”, and file io works. So - writing to /var/tmp/whatever-you-want, and then reading it with another app, is straightforward. Getting to Codea’s Documents directory is a trick, as there’s an ugly hashed directory name that varies from ipad to ipad (assigned on-the-fly as Codea is installed, I gather), and no good way to figure out what that is because there’s no directory services or access to the environment variables (and HOME). If there’s a friendly symlink or such, it’s escaped my notice. os.getenv would work around this nicely, as would simply chrooting us to the Documents directory (and I’ll bet dollars Apple will insist on the latter) - although there is a certain charm in Codea being able to read data in any other app’s Documents directory…

If you manage to figure out the hash (I used ssh to get a shell, then went to /var/mobile/Applications and did “cd */” and looked at where I ended up), then yes - writing to your local project directory or reading from it or anything is straightforward.

I think visual filepickers and all the trimmings would be awesome; I’d actually like to see something like the “air sharing” app does - it makes the Documents directory (for itself only) available as a WebDAV and/or browser interface. So - you put it in sharing mode, then connect and simply copy files to/from the share.

Amusingly, the application that I want to write to tells me this hash as it produces a log file with absolute filenames in it. So I have the functionality that I want.

Turns out that ideviceinstaller -l -o xml produces the hash information (iPad not jailbroken) so I can figure it out for any app. Nifty - while it lasts.

Yes and no. I’m only about 90% sure on this, but so far as I can tell, it gives you the hash for THAT particular install of that app on your ipad. If I install the app - it could (will) have a different hash.

By way of confirmation - my Codea hash is 79C28759-4EC7-467A-B516-37F9AA9A5188 - is yours the same?

For your own personal use, that may be fine, but for something you want to share, it’s not as useful.

Yes, I meant I could get the hash of any of my apps.

My Codea hash is F6EE55A6-A709-4E44-B2ED-72F789BE5BFC

I will be, frankly, amazed if Apple allows this even with a chdir() to the document directory. I would expect a chroot jail at the least.

I think the Apple policy (someone can correct me if I’m wrong) is that your app shall not screw with the files of other apps. So I agree - if I was apple, I’d require jailing to the Codea Documents directory.

Pity. Access to other apps data, even read-only, would be tremendously powerful. IS.