I am new to developing with the Corona SDK as well as Lua. Currently i work strictly with the main.lua file. Is there any way in Lua (im sure there is) to break up the source code into logical, separate files?
Example: 1. Main.lua 2. Entity.lua 3. Settings.lua
Thanks!
objects.lua:
local M = {}
M.a = 3
return M
main.lua:
local objects = require('objects')
println(objects.a) --> 3
A very good discussion about this is available in the Lua users' wiki: http://lua-users.org/wiki/LuaModuleFunctionCritiqued. You should read it.
Here's a sample I wrote to demo what you're asking about: http://developer.anscamobile.com/code/object-oriented-sample-game-framework
EDIT: The forum post no longer seems to exist, so here's a link to download the sample code https://app.box.com/shared/uz5beg19h8
It divides things up into multiple files, and uses a sort of decorator pattern to add functionality like "level" or "floating character".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With