Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to have multiple Lua files when working with Corona SDK?

Tags:

lua

coronasdk

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!

like image 704
AlvinfromDiaspar Avatar asked Apr 11 '11 11:04

AlvinfromDiaspar


2 Answers

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.

like image 74
ponzao Avatar answered Sep 23 '22 18:09

ponzao


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".

like image 24
jhocking Avatar answered Sep 25 '22 18:09

jhocking