Do we need to save and parse JSON, or can we load a simple lua file?

LOVE engine allows love.filesystem.load that returns a function chunk, which you can call to evaluate the content, eg. you can load a lua module that simply returns a lua table.

Does Corona SDK has anything similar? LOVE does support iOS nowadays, so I wonder how they pull that off without triggering Apple’s rule (I heard Apple loosen their rules regarding lua loading).

require() is not really designed for loading map data or animation data (which you might want to unload when changing scenes), so are there any alternatives?

Edit: from what I find Apple’s rule regarding lua loading changes over the year… as long as they are in your resource directory (read only, comes with your app), you should be fine?

answer depends on “when” you’re doing this saving/loading - dev-time or run-time?lua’s dofile() and require() are quite similar (if you leave aside the estoerics like passing arguments and maintaining a list of loaded modules to prevent duplicate loads and such else)

dofile() would theoretically allow you to load lua from anywhere, but Corona wipes dofile()  (and load, loadfile, loadstring) presumably to keep Apple happy.  so you’re left with just require() which Corona patches to work only with the resource directory.

so,… if your file is in your resource directory, then there’s little practical difference between loading it via require() or via dofile() (assuming you don’t NEED any “side effects” of a duplicate load for example).  and if your files only contain “data” (fe, a single big lua table of non-function values of the type you might consider using json for) then require() will perform much better than parsing json.

but if you need something that you can save dynamically, from the user’s device, like persisting config/settings/scores/etc, then you have few choices, and json is the convenient way to go.

https://forums.developer.apple.com/thread/38566

Thx for the answer, yes I do intend to load map data from resource directory. I guess I will have to manually free up package.loaded when needed.

answer depends on “when” you’re doing this saving/loading - dev-time or run-time?lua’s dofile() and require() are quite similar (if you leave aside the estoerics like passing arguments and maintaining a list of loaded modules to prevent duplicate loads and such else)

dofile() would theoretically allow you to load lua from anywhere, but Corona wipes dofile()  (and load, loadfile, loadstring) presumably to keep Apple happy.  so you’re left with just require() which Corona patches to work only with the resource directory.

so,… if your file is in your resource directory, then there’s little practical difference between loading it via require() or via dofile() (assuming you don’t NEED any “side effects” of a duplicate load for example).  and if your files only contain “data” (fe, a single big lua table of non-function values of the type you might consider using json for) then require() will perform much better than parsing json.

but if you need something that you can save dynamically, from the user’s device, like persisting config/settings/scores/etc, then you have few choices, and json is the convenient way to go.

https://forums.developer.apple.com/thread/38566

Thx for the answer, yes I do intend to load map data from resource directory. I guess I will have to manually free up package.loaded when needed.