lua-table Questions

5

Solved

I need to convert a table into a comma separated list in order to save it to a text file. Is there a built in method for doing this in Lua?
Catena asked 5/7, 2011 at 22:35

2

My goal is to have a plugin/dissector that can parse a protocol based on protobuf (UDP). I found on the web an Auto-generate Wireshark/Ethereal dissector plugins for Protocol Buffer messages: https...
Munos asked 22/2, 2017 at 14:55

2

Solved

How do I iterate a simple Lua table, that is a sequence, from end? Example of wanted behavior: local mytable = {'a', 'b', 'c'} for i, value in reversedipairs(mytable) do print(i .. ": " ...
Dereism asked 27/12, 2016 at 17:29

6

Solved

I wanna check if two tables have the same value in Lua, but didn't find the way. I use the operator ==, it seems just to check the same objects, but not the elements in the table. If I have two t...
Polik asked 2/12, 2013 at 9:54

8

Solved

What's the most efficient way to determine if a table is empty (that is, currently contains neither array-style values nor dict-style values)? Currently, I'm using next(): if not next(myTable) th...
Earthwork asked 9/8, 2009 at 22:56

1

I am doing some tests to see where I can improve the performance of my lua code. I was reading this document: https://www.lua.org/gems/sample.pdf and I thought using integers as table indices shou...
Craigie asked 25/12, 2018 at 9:49

3

Solved

I have an array x in Lua. I would like to set head = x[1] and rest = the rest of the array, so that rest[1] = x[2], rest[2] = x[3], etc. How can I do this? (note: I don't care if the original arr...
Otha asked 5/2, 2011 at 23:25

2

Solved

I learned how to redefine the Lua's print() in C++ from this post. (https://mcmap.net/q/631350/-redirecting-redefining-print-for-embedded-lua) Here's the redefined print function that prints varia...
Sardinia asked 1/9, 2018 at 10:19

3

Solved

I wonder if nil is a valid element in a table in Lua. What I don't understand is The following code prints 3 t = {1, 2, 3, nil}; print(#t); But the following prints 4 t = {1, nil, 3, 4}; prin...
Appanage asked 15/8, 2018 at 4:28

4

Solved

i am having a table in lua test = {1,2,4,2,3,4,2,3,4,"A", "B", "A"} I want to remove all duplicate elements in table. Output should be test = {1,2,4,3,"A","B"} EDIT: My try : > items = ...
Blackmun asked 19/11, 2013 at 8:43

3

Solved

I know it's very easy to do in Python: someList[1:2] But how do you this in Lua? That code gives me a syntax error.
Gallinule asked 5/3, 2013 at 13:10

1

Solved

I'm facing an issue with Lua while using the table.sort function. I wrote a little snippet ready for you to test, if you want to convince yourselves. test = {"apple", "Bee", "clown" } table.sort( ...
Zellers asked 10/1, 2018 at 13:39

2

Solved

I want to have a read only table in my Lua program. If ever a key is removed or a key is associated with a new value, an error must be thrown. function readonly(table) local meta = { } -- metatab...
Glossy asked 23/12, 2017 at 23:43

7

Within C code, I have an array and a zero-based index used to lookup within it, for example: char * names[] = {"Apple", "Banana", "Carrot"}; char * name = names[index]; From an embedded Lua scri...
Alphonse asked 23/4, 2013 at 8:7

1

Solved

I'd like to have a write-once table in Lua (specifically LuaJIT 2.0.3), so that: local tbl = write_once_tbl() tbl["a"] = 'foo' tbl["b"] = 'bar' tbl["a"] = 'baz' -- asserts false Ideally, this wo...
Astred asked 3/11, 2017 at 0:29

1

Solved

I have an input file Corn Fiber 17 Beans Protein 12 Milk Protien 15 Butter Fat 201 Eggs Fat 2 Bread Fiber 12 Eggs Cholesterol 4 Eggs Protein 8 Milk Fat 5 This is loaded into a table. I can then ...
Inexpedient asked 30/3, 2017 at 3:23

1

Solved

Continuing to learn Lua. I have wrote a function that removes the first sentence from each line and returns the result as a table of modified lines, where the first sentence was removed. Strangely...
Lovelady asked 8/1, 2017 at 20:49

5

Solved

Let's suppose I want to store a list of element. Including some nil values. The position of the values is significant, and I need to represent the absence of a value in the list at a given position...
Exteroceptor asked 5/11, 2016 at 18:3

2

Solved

sorry i am still learning about lua. could you correct me, why the data from file wont read line by line ? this is my example data in file points.txt : lexxo:30:1 rey:40:2 lion:40:2 prince:50:3 ...
Devora asked 7/11, 2016 at 8:26

2

Solved

Having a bit of a hard time to grasp the concept of inheritance (and metatables) in Lua. The official tutorial doesn't specifically explain how to make a constructor for the child class. The probl...
Namaqualand asked 12/10, 2016 at 17:34

2

I am trying to subtract table from table in Lua, so the return table will be the subtraction of t1 from t2. This seems to be working but is there a more efficient way of doing so ? function arra...
Illyrian asked 14/4, 2014 at 15:11

4

Solved

In Lua, there seem to be two ways of appending an element to an array: table.insert(t, i) and t[#t+1] = i Which should I use, and why?
Hildahildagard asked 24/5, 2011 at 15:14

4

Solved

Lua's implementation of tables keep its elements in two parts: an array part and a hash part. Does such a thing exist in any other languages? Take a look at section 4, Tables, in The Implementati...
Estabrook asked 24/1, 2010 at 2:21

2

Solved

When I run this code through redis EVAL it return no results. Any idea why this is not working? redis-cli EVAL "$(cat bug.lua)" 0 bug.lua local retv = {} retv["test"] = 1000 return retv If I...
Everick asked 19/6, 2014 at 4:24

4

Solved

I am trying to iterate through a lua table but I keep getting this error: invalid key to 'next' I know that index starts off as -8 and I know that there is a table there because it gets the firs...
Samira asked 26/5, 2011 at 11:23

© 2022 - 2024 — McMap. All rights reserved.