How does it work today --- can downloaded lua be loaded dynamically?

Hey all -

Sensitive topic, I know… but it seems most questions and answers on this topic are dated (some more than 5 years ago). I’d like to know if I can do the following on iOS according to today’s developer agreements and Corona SDK’s architecture:

  1. After an IAP, the app will download a lua file from a non-Apple hosted server.
  2. After the download completes, the app will use the new lua file via a require() call.
  3. The new lua module and app can then offer new behaviors/logic/features to the user.

To be clear, the IAP is for purposes of getting new behaviors provided by the downloaded lua and these behaviors do not change the premise of the app or make it do things it’s not supposed to do as a part of its original submission to the AppStore.

I have mocked up the download/require/run parts of the above via the simulator and a local server. Would the iOS runtime environment not work the same way (e.g. prevents loading files from the SystemDocuments dir) ??

There are other app environments (notably react-native) which have a similar ability to dynamically run code that was not present at the time of app submission. And there are plenty of use cases for this strategy (adding new game levels after purchase, providing new filters for a photo app, etc).

So, is this all crazy talk or can it be done without issue from a submission perspective and can Corona allow one to load lua in the iOS runtime as it appears to allow in the simulator?

Thanks!

(And apologies if this has a recent answer. I haven’t found one that is dated after the Apple Developer Agreement changes that occurred around June of 2017.)

Hi @murph and Welcome to the forums.  As of today, you cannot require .lua file that are downloaded from some source. They have to be compiled and packaged with the application.  It’s possible to use the Lua “loadstring()” function to run some dynamic code. This is a legacy issue that Apple has previously banned, but it appears today, they may allow it.

I’ve spoken with Engineering and we may add support for this in a future build, but we have to complete some other projects first.

Rob

Not disagreeing with Rob, because he is correct.

You cannot directly download and replace complied lua scripts out-of-the-box. 

My plugin gives you a way to do this:  https://marketplace.coronalabs.com/corona-plugins/patcher

My plugin allows for the bypassing of any lua file you write for your game.  i.e. If you have a lua file game.lua, you can replace it  by downloading a new one and using patcher to load it.

You can also download new scripts and content for an existing game and run it as if you compiled it in.

https://roaminggamer.github.io/RGDocs/pages/Plugins/patcher/

https://www.youtube.com/watch?v=iHoAr2ZmvWo

One note.  From what I’m seeing, you don’t need to download scripts.

Just have alternate scripts and use them in case you enable the features in IAP.  That would be much easier. 

It also wouldn’t require that you have a server or download any code.

@Rob - thanks for the feedback. Exciting to hear that this ability could be available in a future release. Hopefully not too far in the future! :smiley:

@roaringgamer - I didn’t see your plugin before. I’ll check it out. While I could have some source that shipped with the original submission and can be enabled via IAP, there will be features developed after submission I’ll want users to purchase and download at a later time.

Why not include just the activity and then enable it after IAP?  Seems real simple to me…

Example: So player can jump 5 tiles, after IAP player can jump 10 tiles… does this require a new player.lua to be loaded? Absolutely not as it is simply a variable change.

There are no use cases that absolutely cannot be handled currently with regard to IAP (power, extra moves, etc).

An example

jumpMax = 5 if myIAPUnlocks.megaJump then jumpMax=10 end -- process jump logic now

Thanks for the example, @Sphere Game Studios. The example you provided is something that I will be doing for features that are enabled by IAP and, as you stated, are real simple.

What I’m more interested in is the ability to dynamically load activities that are written after the app is installed and can be purchased by a user later.

You simply write the activities in advance and include them in your game/app.  I don’t get why this has to be more complicated than it needs to be.

A use case might help here?

I guess what you’re asking is “why don’t you just keep releasing new versions of your app with each new version containing all the possible activities up to that point?”

If that is your question, then I’d like to keep the app small and I’d like to avoid frequent app submissions. I don’t see it as complicated.

No what I am saying is player has actions A, B and C as default and with IAP then it has D, E an F then code all possibilities and just release a version that allows A, B, C, D, E and F

If IAP is purchased then process D, E and F, otherwise process A, B and C.

You may think you need framework changes to support what you want and that is an incorrect preposition… you can code this “change” easily and now with current release.

While I understand your example, it doesn’t fit what I am doing. And for the matter, I’m not developing a game.

Have you dealt with a scenario in which what you want to update is orthogonal to what your app already does? Meaning, you’re not replacing A,B,C with D,E,F. Instead, you have to add on a brand new something and that something gets wired into your existing app.

Again - I get that I can keep re-releasing the app with everything included and enable things via IAP… but that doesn’t help with the app size and doesn’t help with release frequency.

Well then drive content from your server if it is a business app.  Just hit a different end point if player has made a purchase?

I don’t know your app so cannot comment, just suggesting some ideas.

Expecting Corona to change for you ain’t gonna happen…

Maybe hit up @rg for some custom dev if you need the help (this is totally something that can be server driven right now)

Note: Submitting regular updates to your app will be much simpler than maintaining (and paying for) your own server to host this code. 

You’re already going to be making updates if you add new IAP items to the IAP list.

Also, then you can fully test your app and ensure there are no issues or surprises. 

While I’d love you to buy my plugin, I think in most users’ cases, it is much better to do regular updates and releases.

Finally, and I could be wrong, regularly updating your app helps it stay higher in the search results.  I think…

PS - @SGS is right.  If you really need this, it is something I can do custom coding for.  i.e. If patcher isn’t just right the solution can be modified.

Code doesn’t add much to the weight of your app, so including the logic in your initial app or in updates isn’t bad. Today you can download images, audio, JSON data that can be easily converted to Lua tables which can easily add additional levels to games without bloating the size of the app and without needing executable Lua.  As @sgs said, you can lock all of this behind your IAP using logic.

Then to add on @roaminggamer’s concept of regular updates, don’t underestimate the marketing value of frequent updates. It can help your app move up charts. Your users don’t see your apps as abandonware.

Rob

Old post but I’d like to chime in here with my perspective. I’m in a similar boat to @murph and think I understand what he is trying to achieve.

In my case, with many small single-activity kids apps (puzzles, coloring books, etc), it is becoming clear that model won’t be sustainable (c.f. Google’s new repetitive content guideline and Apple’s anti-spam). In the past I’ve used cross-promotion in the belief that users will find my other (equally small) apps and keep playing my games. But it doesn’t work that way, for the majority of people. So I need to start bundling multiple apps & activities into single apps.

For example, various puzzle theme apps such as Cats, Dogs, Horses will become a single puzzle app. I could just lump all the content into the app, but the APK size will grow quite a lot because the content is asset-heavy (lots of photos). 

Instead, users will download a core puzzle app, and can then download content packs. This delivery is surprisingly cheap - I’m currently using this approach in some apps and with a content delivery network such as CDN77.com I’m currently delivering 800+ GB per month at a cost of less than $40. To finance it, the user is shown a rewarded video before the download, generating around $400 per month in revenue.

Going beyond bundling similar apps I’m also going to look into bundling different activities into single apps. So you might have a Dinosaur activity app with puzzles, coloring books, etc. Then I might want to make the code as well as assets for these activities downloadable on the fly. There will still be updates from time to time to core code, but I hope to increase retention by not requiring updates to get the latest activities. I’m envisioning combining this with push messages to draw attention to new activities.

Both Google Play and The App Store do not have issues with you downloading content after the fact. Their objection is changing how the code works without an update going through review and the end user making a conscious choice to accept your behavior changes. I don’t know that Google has really ever had an issue with this. Apple did. Apple has eased some of these restrictions and we’ve enabled the loadstring() Lua API to dynamically execute some Lua after the fact.

However, based on your description, I don’t see why you really need it. You can, without issue download content from your web server. You can download data in JSON format that contains information about the puzzle: images, where they should be drawn, sounds, values, etc. The JSON can be read in, turned into a Lua table and your existing puzzle.lua can then have new content to work with.

If for some reason you need to had new code behavior, simply update the app with the new logic. Code doesn’t take up significant storage relative to images and audio, so it wouldn’t bloat your app by any significant amount and it’s well known that reasonably frequent updates to your app can help increase app usage and ranking.

No doubt adding all the art to your base app would make it huge, but you can do everything you want to without having to downloadable Lua code.

Rob

Hi @murph and Welcome to the forums.  As of today, you cannot require .lua file that are downloaded from some source. They have to be compiled and packaged with the application.  It’s possible to use the Lua “loadstring()” function to run some dynamic code. This is a legacy issue that Apple has previously banned, but it appears today, they may allow it.

I’ve spoken with Engineering and we may add support for this in a future build, but we have to complete some other projects first.

Rob

Not disagreeing with Rob, because he is correct.

You cannot directly download and replace complied lua scripts out-of-the-box. 

My plugin gives you a way to do this:  https://marketplace.coronalabs.com/corona-plugins/patcher

My plugin allows for the bypassing of any lua file you write for your game.  i.e. If you have a lua file game.lua, you can replace it  by downloading a new one and using patcher to load it.

You can also download new scripts and content for an existing game and run it as if you compiled it in.

https://roaminggamer.github.io/RGDocs/pages/Plugins/patcher/

https://www.youtube.com/watch?v=iHoAr2ZmvWo

One note.  From what I’m seeing, you don’t need to download scripts.

Just have alternate scripts and use them in case you enable the features in IAP.  That would be much easier. 

It also wouldn’t require that you have a server or download any code.

@Rob - thanks for the feedback. Exciting to hear that this ability could be available in a future release. Hopefully not too far in the future! :smiley:

@roaringgamer - I didn’t see your plugin before. I’ll check it out. While I could have some source that shipped with the original submission and can be enabled via IAP, there will be features developed after submission I’ll want users to purchase and download at a later time.