Questions tagged [lua-table]

This tag refers to the table type in Lua that implements associative arrays.

The table type implements associative arrays. An associative array is an array that can be indexed not only with numbers, but also with strings or any other value of the language, except nil. Moreover, tables have no fixed size; you can add as many elements as you want to a table dynamically.

Tables in Lua are neither values nor variables; they are objects.

Creating table

t = {5, 10, 15, apple="red", banana="yellow" }

Short note about keys

Lua stores all elements in tables generically as key-value pairs. Lua does not differentiate between arrays and dictionaries. All Lua tables are actually dictionaries.

Note that keys are references to objects so you must use the same reference to get the same key into the table.

Useful Link

1403 questions
0
votes
1 answer

lua reading and writing table data

I am using the following lua script to access and read an external lua file: FileStr = "lariatData-sgeT-2012-05-31.lua" Hnd, ErrStr = io.open(FileStr, "r") if Hnd then dofile(FileStr) for Str in Hnd:lines() do print(Str, "\n") …
amber4478
  • 6,433
  • 3
  • 20
  • 17
0
votes
2 answers

How do I make a Lua function return key,pairs to a yet unpopulated table?

I want the key pairs to be tableToPopulate.width = 30 and tableToPopulate.Height = 20 They are currently tableToPopulate[1] = 30 and tableToPopulate[2] = 20 local function X () code, code... return 30,20 end local tableToPopulate = { …
Gullie667
  • 91
  • 6
0
votes
2 answers

Lua objects tables leaking between object instances, but not records

I'm trying to learn Lua, so hopefully this is an easy question to answer. The following code does not work. The variable childContext leaks between all instances of classes. --[[-- Context class. --]]-- CxBR_Context = {} -- Name of…
Dennis Miller
  • 952
  • 1
  • 9
  • 22
0
votes
1 answer

How to create many functions in one table lua? (Corona SDK)

I'm trying to create ncar table with 2 different functions: setup ans main_frame local ncar= { img=display.newImageRect("test_car.png",50,120,true); x=0; y=0; frames=0; setup=function(self) return self; end …
user2136963
  • 2,526
  • 3
  • 22
  • 41
0
votes
1 answer

Corona sdk, functions run in wrong order?

I'm trying to save some data in to a table. I get the data from a database and it works ok. My problem is that the data is not saved in the table. It is a lua table like table = {} and NOT a database table. Maybe it is saved but it looks like the…
Dave
  • 341
  • 1
  • 4
  • 13
0
votes
1 answer

Corona, transition.to upon removal from table

Using Corona, i would like to move object when i delete it from a table. The problem is that i iterate the table on every frame. When x > WIDTH - 50 i would like for the monkey to stop moving in a sinuswave form and jump into the removeMonkeys…
Eyeball
  • 3,267
  • 2
  • 26
  • 50
0
votes
1 answer

Computercraft program in lua

So here's the thing, i'm trying to make a fully customizable UI in computercraft, using lua arrays, and when I use this, ui seems to always be empty function dupChar(char, num) ret = '' for ii=1,num do ret = ret..char end return…
LazyShpee
  • 82
  • 12
0
votes
1 answer

Corona - Touch Events In table objects?

I am trying to use this in a project, but I cannot figure out how to place a touch event listener to each of the icons/objects in the carousel, If someone could provide a quick answer of how to do that I'd appreciate it. local NUM_ITEMS=20; …
0
votes
1 answer

why is my global table being considered nil?

background: I am trying to teach myself Lua and I am having difficulty understanding why a table is being considered nil when it has data inside it. Can anyone break it down for me why I am getting this error message from the code snippet below? It…
toosweetnitemare
  • 2,226
  • 8
  • 33
  • 44
0
votes
1 answer

In onButtonEvent function t.value not updating

I am designing an Odd One Out round for a game that I am developing, every time a button is pressed, the onButtonEvent function is supposed to check if the word selected is the odd one out and then refreshes the buttons with different words. The…
Gooner
  • 387
  • 2
  • 23
0
votes
1 answer

how to use table elements

I'm displaying titles of movies as letter images e.g. A separate image for each letter. Each letter can then be dragged in a space/container. this is my code for displaying the container posX = {} posY = 124 px = 10 containers = {} for i = 1,…
Gooner
  • 387
  • 2
  • 23
0
votes
3 answers

Lua: how use all tables in table

positions = { --table 1 [1] = {pos = {fromPosition = {x=1809, y=317, z=8},toPosition = {x=1818, y=331, z=8}}, m = {"100 monster"}}, --table 2 [2] = {pos = {fromPosition = {x=1809, y=317, z=8},toPosition = {x=1818, y=331, z=8}}, m = {"100…
Jeron
  • 36
  • 4
0
votes
1 answer

Deleting an item from table in lua

Am really struggling very much in deleting an item from table, am creating the table as dynamically,and inserting values in table working really great, but removing values from table making me really trouble. here is my script : local key =…
ssss05
  • 717
  • 7
  • 14
  • 26
0
votes
3 answers

Two index with one value in a lua table

I am very new to lua and my plan is to create a table. This table (I call it test) has 200 entries - each entry has the same subentries (In this example the subentries money and age): This is a sort of pseudocode: table test = { Entry 1: money=5…
swaechter
  • 1,357
  • 3
  • 22
  • 46
0
votes
1 answer

Lua: Way to create tables automatically?

I'm trying to load data values of data categories of a database into tables for further processing. Each data category is supposed to get its own table. Unfortunately, the number of data categories isn't consistent and varies from DB to DB, so I…
Zerobinary99
  • 542
  • 2
  • 8
  • 17