Take array name within array

Asked

Viewed 128 times

3

Well, what I want is the following: take the name of an array within another array, just the name. EX:

local a = 
{
["oi"] = {sim=1, nao=2},
["tchau"] = {sim=2, nao=1}
}
local falas = {}
table.insert(falas, a)

-- Add the values "hi" and "bye" to the table talks. That’s the intention, but I don’t know how you do it.

  • Have you tried using a matrix?

1 answer

5

  • 1

    arrays in Lua start from 1, instead of starting at zero. (you can use table.Insert if you don’t want to worry about it)

  • ah, forget what I said. The n=n+1 at the beginning of the loop is kind of weird but it’s right (never doubt the lhf, hahaha)

  • Thanks, I did: for a, b in pairs(a) of table.Insert(lines, a) end ?

  • @Gabrielsales According to the linked question, no, because the keys have no set order. You can even sort the keys, but preserve order in which they appeared in the source code, I’m afraid that’s not possible. However, I’m new to Lua, so there might be something I don’t know about. (P.S. I found this, will help in something?)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.