Can I "require" a file from "system.DocumentsDirectory"?

I’d like to download a .lua file from the internet, and “require” it in my app. How do I set the “require” path to the “system.DocumentsDirectory” folder?

If this can’t be done, can I save the .lua file from the internet to a directory in which I can require it? [import]uid: 102175 topic_id: 28938 reply_id: 328938[/import]

Very interesting. You could then also make downloadable app modules and such.

Have you tried using the system.pathForFile thing? [import]uid: 67504 topic_id: 28938 reply_id: 116530[/import]

The script I’m trying is:

[lua]network.download( “http://light-sleepers.com/otherbooks/vars.lua”, “GET”, networkListener, “vars.lua”, system.DocumentsDirectory )[/lua]

and then:

[lua]local vars = require(“system.TemporaryDirectory.vars”) --vars is the file I want to require[/lua]

But it doesn’t work. I have to say I’m not really getting the directories structure yet.

I’m trying the system.pathForFile thing but I still can’t figure it out… [import]uid: 102175 topic_id: 28938 reply_id: 116533[/import]

I found an answer to this here: http://developer.coronalabs.com/forum/2011/03/28/require-lua-files-documentsdirectory unfortunately it can’t be done. [import]uid: 102175 topic_id: 28938 reply_id: 116551[/import]

As you found out, no you can’t.

There are two reasons. 1st. Apple doesn’t permit it. Period. 2nd, Your Lua files are compiled into byte code during the build process. Corona doesn’t have code to process Lua to Bytecode in the app it ships to the user.

I’m not sure I would want this feature anyway, of course from Apple’s perspective, only mischief can come from it, but to that, code breaks. It’s the reason we test and test and test before releasing it. Untested code that could make it into the customer’s Documents Directory would be full of potential… errors… Talk about a support nightmare.
[import]uid: 19626 topic_id: 28938 reply_id: 116558[/import]

Could I do it with an XML file? Dowload an XML file from the internet and then read from it and make variables that way? In the XML tutorial it seems like you can read form a file that’s located in system.ResourceDirectory, but I don’t want to waste another day trying it unless you guys let me know that it could work. So tired. [import]uid: 102175 topic_id: 28938 reply_id: 116887[/import]

Maybe you want something like:
http://developer.coronalabs.com/code/ice
or
http://developer.coronalabs.com/code/simple-lua-table-save-load
?
[import]uid: 67842 topic_id: 28938 reply_id: 116896[/import]

Loading XML or JSON data from system.DocumentsDirectory is okay because you’re only loading data, you’re not loading in executable code. While you can use a lua file for data, you could put executable code and that would be against the rules.

[import]uid: 19626 topic_id: 28938 reply_id: 116897[/import]

So, you’re telling me there is a chance :smiley:

Maybe I should explain what I’m trying to achieve - it’s actually quite simple. I want to make a “more apps” page with links that open the iTunes store. I was hoping to just have a webPopup with this in it: http://light-sleepers.com/otherbooks/otherbooks.htm (with graphics of course), but the links in the webPopup can’t open the iTunes store. And I need to be able to add more links to that window.

Then I thought of doing this:

  
local vars = require("vars")  
  
 local link1 = display.newRect(110, 20, 100, 100)  
 link1:setFillColor (100, 100, 100)  
 link1.alpha = 1  
  
 function link1:tap( event )  
 system.openURL( app1 )   
 end  
 link1:addEventListener("tap", link1)   
--  
 local link2 = display.newRect(110, 130, 100, 100)  
 link2:setFillColor (100, 100, 100)  
 link2.alpha = 1  
  
 function link2:tap( event )  
 system.openURL( app2 )   
 end  
 link2:addEventListener("tap", link2)   

where the “vars.lua” file would be DL-ed from the internet and define the variables “app1” “app2” and so on as the required addresses. That’s where this post started.

But if I can DL and XML file instead of LUA and get the addresses from there, that might work right?

Please feel free to suggest any other way I might achieve this, as I am just an animator in a programmer’s world :slight_smile:

@SUHADA I’ll look at the links you posted and see if any of them help, thanks. [import]uid: 102175 topic_id: 28938 reply_id: 116905[/import]