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.l开发者_运维技巧ua 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".
You don't need to only work with main.lua file. You can create separate .lua file as you need it like -
1- If you are using many scenes/views/classes for this you can create your separate .lua file for different scenes/views/classes and call these separate .lua files by using storyboard.
2- You can also create separate .lua files for creating objects which you can access in your any class.
3- There are many .lua files like appirater.lua , ui.lua, json.lua provided.
精彩评论