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?
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...
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 .. ": " ...
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...
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...
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...
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...
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...
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 = ...
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.
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( ...
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...
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...
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...
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 ...
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...
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...
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...
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?
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...
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...
© 2022 - 2024 — McMap. All rights reserved.