pass an array objects in Corona with class

I'm creating an app with Corona structured in Class and I have a problem when I want pass an array objects for create an object. I have this:

main.lua

local SurpriseBoxClass = require("SurpriseBox")
local BoxClass = require("Box")

local box1 = BoxClass.new('palo', 'images/chestClose.gif', 'OPEN')
local box2 = BoxClass.new('moneda', 'images/chestClose.gif', 'OPEN')
boxes = { box1, box2 }

local game = SurpriseBoxClass.new(boxes)

SurpriseBox.lua

local SurpriseBox = {}
local SurpriseBox_mt = { __index = SurpriseBox }

function SurpriseBox.new(boxesAux)
 local object = {
   boxes = boxesAux
 }
 return setmetatable( object, SurpriseBox_mt )
end

The problem is when I want to print the content of array in a method of SurpriseBox, and the program said me that the array is nil if for example I do this:

print(boxes[0])

What can I do?

Thanks!

Answers


Lua tables are 1-based.

Try print(boxes[1], boxes[2]).

It will print the table id. If you need to print the contents of the table, you must iterate over its fields, or use a custom printer that does it for you (see "Print a table recursively").


Need Your Help

Core Data: Fetched Results Controller causing over release/crash

objective-c ios core-data nsfetchedresultscontrolle nsentitydescription

I am using core data, and have a UITableViewController which loads the data from core data. This is a modal view and if I load the modal view for the third time, it crashes with EXC_BAD_ACCESS.

jQuery Ajax SyncLock

jquery ajax synclock

I have a couple of buttons that users can click to load content with jQuery's $.ajax. All the buttons load the content into the same div tag. The problem is that if users click multiple times quick...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.