lua-table Questions
1
Solved
Excerpt from Lua 5.3 manual:
_G
A global variable (not a function) that holds the global environment (see §2.2). Lua itself does not use this variable; changing its value does not affect any envir...
Amp asked 10/3, 2016 at 7:24
2
Solved
I came across tables that have square brackets around keys:
local commands_json =
{
["request"] = {
["application"] = PW_APPLICATION,
["push_token"] = deviceToken
...
1
I need to use Redis HMGET from a Lua script and extract specific values in following code.
But redis.call('HMGET', table_key, hkey1, hkey2, ...) return a flat array of {hkey1, val1, hkey2, val2, .....
1
Solved
I'm not sure how, but we managed to create a table with two keys exactly same. When performing for loop over pairs of the table and printing keys and values we get:
1 true
1 true
and we thought ...
3
Solved
I have this array, with some values (int) and I want to check if a value given by the user is equal to a value in that string. If it is, output a message like "Got your string".
Example of the lis...
2
Solved
I'm learning Lua to build scripts for a flight simulator.
I have a CSV file that appear like this:
Poti city, Poti,red,-295731.42857144,617222.85714285
Lanchhuti city, Poti,red,-299217.14285715,...
2
I've been trying to find a way to remove a string from a table kind of like this:
myTable = {'string1', 'string2'}
table.remove(myTable, 'string1')
but I haven't been able to find anyway to do i...
Vagary asked 27/9, 2015 at 5:40
2
Solved
Is there a shorter way to do this:
local thisismytable = {
non = sequitur
}
thisismytable.whatismytable = thisismytable
Any help would be appreciated.
I don't want to re-create pre-existing fun...
2
Solved
Could somebody explain to me why table.unpack() returns the first table element only when it is used in a function call with additional parameters after table.unpack()?
Here is some demo cod...
2
Solved
Is there any way to loop trough a table like the one below in the same order as it's written?
local tbl = {
["hello"] = 1,
[2] = 2,
[50] = 3,
["bye"] = 4,
[200] = 5
}
What I mean is that wh...
6
I need to check if a member exists in a table that isn't at the next level, but along a path of members.
foo = {}
if foo.bar.joe then
print(foo.bar.joe)
end
this will cast an attempt to index f...
2
Solved
How does lua handle a table's growth?
Is it equivalent to the ArrayList in Java? I.e. one that needs continuous memory space, and as it grows bigger than the already allocated space, the internal ...
Bondon asked 28/4, 2015 at 19:37
1
Solved
I'm trying to iterate over a table of tables in Lua and output:
The key of each table.
The key / value pair of each entry in each table.
Here is the code:
void print_table(lua_State *L)
{
lua...
2
Solved
I'm aware of the weak tables functionality in Lua, however I would like to have a weak reference with a single variable.
I've seen this proposal which suggests an API as follows:
-- creation
ref ...
3
Solved
I want to create a table like
myTable = {
[0] = { ["a"] = 4, ["b"] = 2 },
[1] = { ["a"] = 13, ["b"] = 37 }
}
using the C API?
My current approach is
lua_createtable(L, 0, 2);
int c = lua_get...
4
Example:
table1 = {2,3,1}
table2 = {a,b,c}
to
table1 = {1,2,3}
table2 = {c,a,b}
3
Solved
I would want to sort a table alphabetically. Except numbers.
The code below shows how the table is sorted with comparator function:
function( a,b ) return a.N < b.N end
Gives me:
obj = {
...
2
Solved
How can I split a Lua table containing few sub-tables into two tables without changing the original table.
e.g.
split tbl = {{tbl1}, {tbl2}, {tbl3}, {tbl4}} into subtbl1 = {{tbl1}, {tbl2}}, subtbl...
3
Solved
I'm wondering if anyone can confirm whether you can trust ipairs() to; return all indices in order, for a table that's index-complete but unsorted.
We have code all over our project that clones ta...
3
Solved
I'm trying to figure out the equivalent of:
foo = []
foo << "bar"
foo << "baz"
I don't want to have to come up with an incrementing index. Is there an easy way to do this?
2
Solved
1
Solved
1
In Lua, I know there is
table.remove(array, index)
Is there a fast way to remove and return X elements from the array (without just repeated calls to table.remove)?
2
I have a project that calls for a relational database like structure in an environment where an actual database isn't possible. The language is restricted to Lua, which is far from being my stronge...
© 2022 - 2024 — McMap. All rights reserved.