Abiding by Apple's Terms

Here is a senario: 

We have a game. In this game, the user can download content - more art and characters. The images are help in zip folders that are hosted on our server and downloaded to the device. 

– so far so good –

If we want to pack our images into an image sheet, through a program like Texture packer, we must include the images and lua folder in our zip.

The apple developer terms states that no app can download any code. Would the lua file downloaded with the images be cause for the app’s rejection?

Yes it would, because you could for example submit an app that does something simple just to get it approved, and then drastically change the behaviour to do something illegal once it is released.  

Also, I don’t think that Corona itself can use downloaded code as Corona package all of your Lua files into a single file when building the app.

However what you can download the packed image, and you can download other file types (e.g. json files). The Lua file created by TexturePacker just returns a table, so you could easily put that data into a json table, download that, and then decode it back to a Lua table at runtime.

I’ve made a quick example for you  :slight_smile:

Use this code in the simulator to create a json file which you can then upload to your server or wherever you planned to host the downloadable data:

--load a texture pack lua file local tp = require("yourTexturePackLuaFile") --save its data to a temp table which does not include the 2 functions local tempTable = { sheet = tp.sheet, frameIndex = tp.frameIndex } --save the temp table to a json file local json = require("json") local savePath = system.pathForFile("myTexPack.json", system.DocumentsDirectory ) local saveFile = io.open(savePath, "w") saveFile:write(json.encode(tempTable)) io.close(saveFile) --then put it on your server or whatever you want to do with it

Obviously the required file “yourTexturePackLuaFile” should be replaced with the name of your own Lua file that TexturePacker generated for you. 

Then, in your game code download the json file, retrieve the string from it, and then convert it back to a Lua table with the same functions that TexturePacker gave it (getSheet and getFrameIndex). This does need to be in your main project:

--this will hold the 'downloaded' lua table once it is generated local myLuaTexPackData = nil local function fileDownloadListener(event) if ( event.isError ) then print( "Network error - download failed" ) elseif ( event.phase == "began" ) then print( "Progress Phase: began") elseif ( event.phase == "ended" ) then local filename = event.response.filename local directory = event.response.baseDirectory -- create a file path for corona i/o local path = system.pathForFile( filename, directory ) -- will hold contents of file local file, contents -- io.open opens a file at path local file = io.open( path, "r" ) -- read all contents of file into a string local contents = file:read( "\*a" ) -- close the file after using it io.close( file ) --this will create the lua table that you would have originally received from TexturePacker local json = require("json") myLuaTexPackData = json.decode(contents) --and add the 2 functions to it function myLuaTexPackData:getSheet() return myLuaTexPackData.sheet; end function myLuaTexPackData:getFrameIndex(name) return myLuaTexPackData.frameIndex[name]; end end end --download the file network.download( "http://www.yourserver.com/myTexPack.json", "GET", fileDownloadListener, params, "myTexPack.json", system.DocumentsDirectory )

I’ve just done a quick test and it worked for me, you’ll just need to update the server and file names accordingly. You will need to put in some failsafes so that if the image is downloaded but the json data fails to download (or vice versa) you don’t get crashes.

Thanks for the example Alan I’ll give that a try! :slight_smile:

Yes it would, because you could for example submit an app that does something simple just to get it approved, and then drastically change the behaviour to do something illegal once it is released.  

Also, I don’t think that Corona itself can use downloaded code as Corona package all of your Lua files into a single file when building the app.

However what you can download the packed image, and you can download other file types (e.g. json files). The Lua file created by TexturePacker just returns a table, so you could easily put that data into a json table, download that, and then decode it back to a Lua table at runtime.

I’ve made a quick example for you  :slight_smile:

Use this code in the simulator to create a json file which you can then upload to your server or wherever you planned to host the downloadable data:

--load a texture pack lua file local tp = require("yourTexturePackLuaFile") --save its data to a temp table which does not include the 2 functions local tempTable = { sheet = tp.sheet, frameIndex = tp.frameIndex } --save the temp table to a json file local json = require("json") local savePath = system.pathForFile("myTexPack.json", system.DocumentsDirectory ) local saveFile = io.open(savePath, "w") saveFile:write(json.encode(tempTable)) io.close(saveFile) --then put it on your server or whatever you want to do with it

Obviously the required file “yourTexturePackLuaFile” should be replaced with the name of your own Lua file that TexturePacker generated for you. 

Then, in your game code download the json file, retrieve the string from it, and then convert it back to a Lua table with the same functions that TexturePacker gave it (getSheet and getFrameIndex). This does need to be in your main project:

--this will hold the 'downloaded' lua table once it is generated local myLuaTexPackData = nil local function fileDownloadListener(event) if ( event.isError ) then print( "Network error - download failed" ) elseif ( event.phase == "began" ) then print( "Progress Phase: began") elseif ( event.phase == "ended" ) then local filename = event.response.filename local directory = event.response.baseDirectory -- create a file path for corona i/o local path = system.pathForFile( filename, directory ) -- will hold contents of file local file, contents -- io.open opens a file at path local file = io.open( path, "r" ) -- read all contents of file into a string local contents = file:read( "\*a" ) -- close the file after using it io.close( file ) --this will create the lua table that you would have originally received from TexturePacker local json = require("json") myLuaTexPackData = json.decode(contents) --and add the 2 functions to it function myLuaTexPackData:getSheet() return myLuaTexPackData.sheet; end function myLuaTexPackData:getFrameIndex(name) return myLuaTexPackData.frameIndex[name]; end end end --download the file network.download( "http://www.yourserver.com/myTexPack.json", "GET", fileDownloadListener, params, "myTexPack.json", system.DocumentsDirectory )

I’ve just done a quick test and it worked for me, you’ll just need to update the server and file names accordingly. You will need to put in some failsafes so that if the image is downloaded but the json data fails to download (or vice versa) you don’t get crashes.

Thanks for the example Alan I’ll give that a try! :slight_smile: