Storing "userdata" items in a table?

Hello Lua experts,

Can “userdata” items created by Lua/Corona be stored in a standard table for organization and eventual cleanup? I am loading some sounds into memory using the audio API and "audio.loadSound( 'file' )". When I use a local variable (pointer) in the assignment of that, and then print its value to the terminal afterward, it is a “userdata” item, i.e. "userdata: 0x1ee82db0"

What I would like to do is to load several sounds into memory (around 10 of them). These sounds will be played frequently and thus I want to keep them in memory. For organization purposes, I would like to store the Lua references to them (the “userdata” references) in a standard holding table, for example…

local coreSounds = {}  
coreSounds[1] = audio.loadSound( 'file' )  
coreSounds[2] = audio.loadSound( 'file' )  
--etc.  

So is it allowable to store “userdata” items in a holding table just like you can with other tables, variable, strings, etc.? If so, can I later loop through this table by the count of its children (in reverse order), and dispose of the audio in that manner?

I’m actually not clear on what “userdata” entails in Lua, or how it compares to standard tables. Any help clarifying this is appreciated. :slight_smile:

Brent Sorrentino
Ignis Design
[import]uid: 9747 topic_id: 23754 reply_id: 323754[/import]

Yes you can. Userdata is data in C. Although you can’t manipulate it in Lua directly, you can store pointers to it in any Lua variable as you normaly do with any other Lua pointer for tables.

To manipulate such data you need to make use of Corona functions that do so, like play sound, dispose, load and such. This functions will actually call some C code that will then handle it. [import]uid: 61899 topic_id: 23754 reply_id: 95549[/import]

Thank you CluelessIdeas! This clarifies it for me. Now I can organize my sounds into tables for easy management and cleanup.

Brent
[import]uid: 9747 topic_id: 23754 reply_id: 95756[/import]