3

I have an app I'm writing that has a set of embedded lua scripts in them. I'd like to be able to edit the scripts on the iPad – is this possible?

The workflow I was thinking of was:

  1. start my app and test;
  2. go to my text editor on the iPad and make changes to the lua script;
  3. close my app;
  4. restart my app to reload the script;
  5. goto 1.

EDIT: I can add the “Open In” option to my app and open the text file as per this question, however, once I do that does the text editor then save the file back to where it came from? or does it just use a copy? This assumes I can find a text editor that will open lua files, I imagine there’s one around somewhere.

Community
  • 1
  • 1
daven11
  • 2,905
  • 3
  • 26
  • 43
  • 2
    Apps are sandboxed, so anything you place in the documents folder can't be accessed by another application. I would suggest building a simple text editor into your app. – danielbeard May 09 '12 at 01:24
  • I was trying to avoid this - given the number of text editors available you'd think it would be possible :-( – daven11 May 09 '12 at 01:33
  • Yeah, at least there is plenty of examples out there. Just out of curiousity are you going for something like Codea - http://twolivesleft.com/Codea/ ? – danielbeard May 09 '12 at 01:37
  • 1
    Just came across UIPasteboard which might help you achieve what you are trying to do - http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIPasteboard_Class/Reference.html – danielbeard May 09 '12 at 01:51
  • No, just using embedded lua - the user will never see it. It would be nice if I could just make my code an .so and run it from codea or similar, but that's not possible either I believe. – daven11 May 09 '12 at 01:53
  • That's a very good idea, I can just paste it back into my app and save. Thanks! – daven11 May 09 '12 at 01:57
  • I’m **way** in over my head as to technical implementation, but what your are looking for seems to be the “Open In” workflow as implemented when opening Mail attachments or Safari downloads. Your app needs to implement sending to other applications having registered as text editors. These get a copy into their sandbox they can edit, and if they implement “Open In” themselves and your app registers as an editor for `.lua` files, they can send a copy back to your app’s sandbox – where you're free to have it overwrite the original. The iOS SDK docs should have the details under LaunchServices… – kopischke May 09 '12 at 15:01
  • That's a good idea, just have to find a text editor that does open in for lua files and then bounce them back and forwards. Do you want to make this an answer so I can tick it? – daven11 May 11 '12 at 02:51
  • @daven11: find my expanded answer [below](http://stackoverflow.com/a/10548966/990363. – kopischke May 11 '12 at 09:40

3 Answers3

1

As @danielbeard correctly stated this will not work as straightforwardly as expected on a desktop (or more permissive mobile) OS due to iOS sandboxing model, which effectively constrains application data to the application itself, although it is worth noting the issue at hand is not the sandboxing per se, which also exists in newer versions of OS X, but the fact iOS offers no unifying file system layer which is mirrored into applications’ sandboxes. You can plainly and pretty simply see that for yourself by editing a text document on your desktop in Lion’s TextEdit. TextEdit sees the document being located in its sandbox – ~/Library/Containers/com.apple.TextEdit/Data/Desktop, but it is also clearly saved onto your desktop ~/Desktop – at the same time; both directories are, for the purpose of the sandbox, one.

Sandbox me once, edit me twice

the cross-application file layer does not exist in iOS. This means that in iOS, it is not possible to edit one and the same physical copy of a file in multiple applications, as every app needs a copy in its own sandbox. It is however possible to “pass” files from app sandbox to app sandbox (strictly speaking: to copy them) via the “Open In” mechanism supported since iOS 3.2, as seen when opening Mail attachments in other apps.

Open me up

If your app implements the ability to forward its .lua documents via this mechanism, any text editor recognizing the file type can receive a copy into its own sandbox. I’m hazy as to implementation details, not being an iOS dev myself, but if the rules of UTI declaration from OS X and some stuff I have observed while using my iDevices holds true, you can even insert the file type into the public.text UTI hierarchy in your own app, which will add support for it to all text editors on the device.

If the receiving editor implements “Open in” too, and your app has registered as being able to edit .lua files, the editor can later copy the edited file back to your app’s sandbox. What happens there (de-duplication, versioning, overwriting with or without prompting) would be up to you, within the constraints imposed by the iOS SDK, which I know nothing about.

The following Apple Developer documents may provide a useful starting point:

Community
  • 1
  • 1
kopischke
  • 3,393
  • 1
  • 21
  • 40
0

You can do all this and much more if you jailbreak your iPad and installed OpenSSH.

I develop using Moai, an SDK for writing games in Lua recently adopted by Double Fine. I can code directly on the iPad using my editor of choice (Vim) via an SSH session to localhost (using Prompt, an iOS SSH client). I map a hotkey that restarts app. With a bluetooth keyboard, it's as close as the iPad gets to being a laptop.

You can also use something like ExpandDrive to map the iPad's filesystem into your desktop filesystem. Then you can browse files and edit them as if they were on your desktop machine, totally wirelessly. You can map a key in your editor to restart your app via SSH, so the workflow becomes:

  1. Edit Lua script(s)
  2. Hit key to relaunch your app and see changes.
Mud
  • 28,277
  • 11
  • 59
  • 92
0

You can't access from one application's sanbox to other application's sanbox in iOS without jailbreak.

Maksim
  • 2,054
  • 3
  • 17
  • 33
  • You cannot reach **into** another app’s sandbox, that much is correct. But there is an orderly way of sending data **from** one sandbox to another, arbitrated by iOS’ flavor of LaunchServices: “Open In”. See [my answer](http://stackoverflow.com/a/10548966/990363). – kopischke May 15 '12 at 08:11