Does createProject() work in exported apps?

Hello,
a couple of months back I tried using the createProject( key ) command. While it worked fine in Codea, it was apparently unsupported in the runtime used for exported apps and thus I received an error message when running the project in XCode. Has this changed or is createProject() still limited to be used within Codea only? If it is still unsupported, is there a chance the command will be included in the runtime at some point?

I’m curious how you would use something like createProject in an exported app. Could you tell me what sort of functionality you had in mind that this function would help you achieve?

I’m working on a level editor/game engine and would like to export my projects from there straight to Codea. Creating a project for Codea within the level editor would make it quite straightforward to continue working in Codea afterwards.

Furthermore, I’m currently looking into adding scripting to the editor. Using createProject() and readProjectTab() I could run code that is created by the level editor at runtime and instantly play my levels.

Ah I see. In that case I wouldn’t recommend createProject, that’s more for creating projects inside Codea, which is why it’s disabled in the exported runtime.

One way to do it would be to use saveText to create all the Lua files you need.

From there zipping it up and invoking the share sheet (via a native extension — that’s where it gets tricky) would be ideal.

Otherwise you could copy the code to the the clipboard by using pasteboard.text = <entire project string> then tell the user to long-press on the Codea add project button to paste the exported code as a new project

Thanks for the explanation :slight_smile:

Using the clipboard sounds promising and the easiest to implement. The text would be pasted into one tab, though, and all the assets such as images would have to be imported manually into Codea. I’m not sure whether this works well with larger scale projects.

Could I save the necessary files via saveText() into the documents folder of my app and have the user zip it manually in the files app and then send it to Codea?

You could do that. The best thing would be to write a native CodeaAddon that exposes a function to Lua — like write your own createProject essentially

That function could be given the Lua code and asset locations, then it could write the files, create an Info.plist, put it all in a “Project.codea” folder. Then zip it up and show the Share Sheet to the user. That file could be imported directly into Codea

This involves writing some Objective-C and C code, though!

That sounds quite complicated, at least when considering that I’ve never written Objective-C code and have no experience in programming a native iOS-App.

I guess for now, I’ll stick to using the clipboard and see how this works out. But I guess, I’ll have to find a more convenient solution in the long run.
Is there a reason why createProject can’t be used? It still seems like the best solution to me.

Anyway, you’ve been a tremendous help. Thanks!

I hadn’t thought about a use case of developing an app that generates Codea projects, it’s really interesting.

I guess the createProject API could be used to create a project in the current Documents folder… then you could use it just like you could use in Codea.

@Simeon Sorry for the late response. Would that be an option?

@Simeon I’ve tested using the pasteboard for a very small example. It works, but I don’t think it’s ideal. It’ll probably get very unorganized once a project becomes larger and spans a more than a few hundred lines of code.

The pasteboard actually supports creating multiple tabs btw

If you long press on a project with multiple tabs in the browser, choose “Export”, then “Copy to Pasteboard” you will see that there are special comment delimiters in the code (I think they start like --# Tab Name) when you do “Paste Into New Project” Codea will look for these delimiters and make tabs in the resulting project

@Simeon Thanks, that’s great to know! So if the generated code starts with --# Tab Name, it will create tabs automatically? How can you do “Paste Into New Project”? I haven’t seen that as an option. Will give this a try, it definitely sounds promising.

Would it be difficult to adapt the createProject API to support creating a project in the documents folder?

@Leon if Codea detects that the pasteboard has a line with the text --# Main it assumes that the pasteboard contains a Codea project and shows the “Paste into Project” option when you long-press the New Project button

You can try it by:

  • Long press a project
  • Choose “Export”
  • Tap “Copy Project Code”
  • Close the “Export Project” window
  • Long press “Add New Project”
  • Choose “Paste Into Project”

If you paste the copied project text elsewhere you can see how it is structured with --# delimiters for tabs

@Simeon Thanks! I’ve just tried your suggestion and it works perfectly :slight_smile: