lua-table Questions

15

ORIGINAL POST Given that there is no built in function in Lua, I am in search of a function that allows me to append tables together. I have googled quite a bit and have tried every solutions I st...
Exorable asked 11/9, 2009 at 13:27

3

In my main coroutine, I am removing or adding entries from a table depending on user operations. In the background, I'd like to iterate over the entries in the table. I don't mind particularly if I...
Folacin asked 29/5, 2011 at 11:41

8

Solved

What I'm trying to do is display the content of table using the following code in Lua. local people = { { name = "Fred", address = "16 Long Street", phone = "123456" }, { name = "Wilma", ...
Indoaryan asked 30/1, 2017 at 17:50

4

Solved

Is there an easier way to do this? I need to get the very first value in a table, whose indexes are integers but might not start at [1]. Thx! local tbl = {[0]='a',[1]='b',[2]='c'} -- arbitrary key...
Eulaheulalee asked 8/1, 2015 at 22:5

7

Solved

I want to store a lua table where the keys are other lua tables. I know that this is possible BUT I want to be able to do look ups in the table using copies of those tables. Specifically, I want to...
Selfrising asked 8/2, 2012 at 21:20

2

Solved

I have a lua table that I use as a hashmap, ie with string keys : local map = { foo = 1, bar = 2 } I would like to "pop" an element of this table identified by its key. There is a table.remove()...
Tarnation asked 18/11, 2009 at 20:51

1

how can I override some color scheme value in neovim lua config file? I am trying to use .lua instead of .vim. Previously in my init.vim file I have this to override some settings I want to enable ...
Humfrey asked 17/2, 2022 at 5:10

16

Solved

Recently I wrote a bit of Lua code something like: local a = {} for i = 1, n do local copy = a -- alter the values in the copy end Obviously, that wasn't what I wanted to do since variables ho...
Tace asked 12/3, 2009 at 21:52

7

Solved

I have a key => value table I'd like to sort in Lua. The keys are all integers, but aren't consecutive (and have meaning). Lua's only sort function appears to be table.sort, which treats tables as ...
Vharat asked 10/1, 2010 at 20:9

6

Solved

How do I delete all elements inside a Lua table? I don't want to do: t = {} table.insert(t, 1) t = {} -- this assigns a new pointer to t I want to retain the same pointer to t, but delete all el...
Rabbit asked 2/2, 2011 at 21:58

10

Solved

I need to merge two tables, with the contents of the second overwriting contents in the first if a given item is in both. I looked but the standard libraries don't seem to offer this. Where can I g...
Sacksen asked 16/8, 2009 at 3:18

7

How do I get the highest integer in a table in Lua?
Teal asked 3/3, 2011 at 8:3

2

I have a Lua table that I am trying to sort. The table's format is as follows: tableOfKills[PlayerName] = NumberOfKills Which means, for example, if I had a player named Robin with a total of 8 ...
Vitriform asked 29/3, 2013 at 15:28

2

Solved

I need to know how to retrieve the key set of a table in lua. for example, if I have the following table: tab = {} tab[1]='a' tab[2]='b' tab[5]='e' I want to be retrieve a table that looks like ...
And asked 1/10, 2012 at 13:33

4

I have gone through many questions and Google results but couldn't find the solution. I am trying to sort a table using table.sort function in Lua but I can't figure out how to use it. I have a t...
Jeffers asked 2/10, 2014 at 11:59

5

Solved

So, I have a table something along these lines: arr = { apples = { 'a', "red", 5 }, oranges = { 'o', "orange", 12 }, pears = { 'p', "green", 7 } } It doesn't seem like it's possible to access...
Cardcarrying asked 2/7, 2013 at 22:37

2

Solved

I have this table in lua: local values={"a", "b", "c"} is there a way to return the index of the table if a variable equals one the table entries? say local onevalue = "a" how can I get the ...
Majormajordomo asked 9/7, 2016 at 13:18

12

Solved

If I have a list of items like this: local items = { "apple", "orange", "pear", "banana" } how do I check if "orange" is in this list? In Python I could do: if "orange" in items: # do somethi...
Eckman asked 17/3, 2009 at 21:56

3

Solved

I'm trying to call a function in Lua that accepts multiple 'number' arguments function addShape(x1, y1, x2, y2 ... xn, yn) and I have a table of values which I'd like to pass as arguments value...
Fascinate asked 16/3, 2014 at 6:45

4

Solved

Is there a way to use the arg 2 value of table.concat to represent the current table index? eg: t = {} t[1] = "a" t[2] = "b" t[3] = "c" X = table.concat(t,"\n") desired output of table co...
Manure asked 18/3, 2013 at 13:6

4

Solved

I'd like to find out how much memory a Lua table is using - without iterating through the table contents and counting up the usage. Is there a Lua 5.1 function or 3rd party library that could help ...
Nancienancy asked 17/3, 2010 at 11:54

5

Solved

Is there a method for checking if a table contains a value ? I have my own (naive) function, but I was wondering if something "official" exists for that ? Or something more efficient... function t...
Nameplate asked 17/2, 2010 at 16:32

9

Solved

I don't understand the rationale behind the decision of this part of Lua. Why does indexing start at 1? I have read (as many others did) this great paper. It seems to me a strange corner of a langu...
Tuscarora asked 7/5, 2010 at 1:52

8

Solved

I am wanting to convert a 2d lua table into a string, then after converting it to a string convert it back into a table using that newly created string. It seems as if this process is called serial...
Dunstable asked 20/5, 2011 at 16:59

5

Solved

I may have missed this, but is there a built-in method for serializing/deserializing lua tables to text files and vice versa? I had a pair of methods in place to do this on a lua table with fixed...
Sverige asked 31/1, 2012 at 4:9

© 2022 - 2024 — McMap. All rights reserved.