since everything in Lua more or less seem to make use of tables, i’ll have to dive into this pool and test things out
instant gratification, you know
here’s my progress so far:
table constructors are the curly braces { }
TheSupremeTable = {}
a table can be empty but still be a table (?)
tables can have keys and values that are connected to each other somehow
when i experiment it seems that i can put virtually anything in a table:
AnotherTable = {
["msg"] = "This is a message",
["the_meaning_of_life"] = 42
}
print(AnotherTable["msg"], ": the meaning of life is ", AnotherTable["the_meaning_of_life"])
will print out “This is a message: the meaning of life is 42”
note: i had some troubles with this at first because i forgot the quotation marks in the keys (for exampe i wrote [msg] instead of [“msg”])
it seems there is an alternative way to access stuff in tables, maybe this is more common for renoise scripts:
it’s actually in a table called “InstrumentMidiOutputProperties”
which in turn is in a table called “renoise”
is this correct?
the above way of having tables inside tables inside tables is called having “nested tables” (what would the verb be? something like “look mom, i’m nesting tables over here”?)
I’m guessing “ipairs” means “integer pairs”, because you are working with a table organized by numerical order
“pairs” on the other hand is used for traversing associate arrays (tables organized by string value)
You also have ripairs (reverse ipairs) which is useful if you are doing something that remove entries from the table as you are processing it (try looping through a table from the beginning while removing entries? It won’t work).
It should be as simple as copying the table - quoting from the Lua Standard API:
-- Copy the metatable and all first level elements of the given table into a
-- new table. Use table.rcopy to do a recursive copy of all elements
table.copy(t) -> [table]
-- Deeply copy the metatable and all elements of the given table recursively
-- into a new table - create a clone with unique references.
table.rcopy(t) -> [table]
Not actually trying to use them for anything constructive yet (hence it being in the Beginners Sandbox), as I said just trying to get my head around the whole paradigm, but thanks for the reply. Got it to work although had to check the API to get a grip of the syntax compared to how you presented it.
b_table = table.rcopy(a_table) – is how I managed to use it