Try print(ncat(tab, ” “, 4,3)) in the above example if you want to see it (not) happen. Also, if b is larger than e – that is, if it’s told to start after the row it’s told to end with – the function will return an empty string. Using other data types, as we will begin to do in a couple lessons, will not give you any normal output. This only really works if all the values are strings or numbers. Print(ncat(tab, ” “,4)) - starting at 4th row If table.insert worked like that, what would be the point compared to using tablekey value I checked the lua.org documentation, and it does specify optionally to add the key for (table, key, value) but I have never seen it used this way and its perfectly possible that it doesnt function this way in Lua 5.0.1 (Demigods Lua), especially. Print(ncat(tab, ” “,1,4)) - first 4 rows only
Print(ncat(tab, “:^D”)) - silly face between each Print(ncat(tab, ” “)) - space between each value If you want, a list of values can be specified when you create the table: That makes a table that starts off empty. The fastest way to declare a table is by assigning a variable name to an empty pair of curly brackets: But first, we need to make the table! Creating Tables That happens a lot in some languages, but not much in Lua.) If you stick a row into the middle of the list, the higher numbers will bump up one, and removing a row causes others to shift down and fill the gap. This function returns the value of a query string variable passed into the survey where urlkey is the URL variable key. A zero-indexed list or array begins its numbering with 0. (You will sometimes hear someone refer to such a list as one-indexed, meaning that the beginning of the list is identified as item 1. The first row’s key is 1, the next is 2, and so on. Each list item, called a row or record in the table, has as its key a whole number. ArraysĪn array is probably the most straightforward and easily understood kind of table.
Not all languages can do that, but throughout this course you’ll not only make sense of it, but learn some awesome Code Fu moves to do amazing things with it. It’s weird enough that you can use, as key, value or both, strings, objects, and even other tables! Craziness. 4: table.remove (table, pos) Removes the value from the table.
3: table.maxn (table) Returns the largest numeric index. 2: table.insert (table, pos, value) Inserts a value into the table at specified position. We’ll cover the nil value in a different lesson. ncat (table, sep, i, j) Concatenates the strings in the tables based on the parameters given. As an example of how something simple to say can be complex and confusing to understand: both the key and the value can be any valid Lua value but nil… usually. Essentially, it is a list in which each item has 2 parts: (1) a key (also called an index), which is the name of the item, a way to tell the table which thing you want to look at and (2) the value, which is the actual data. table.insert takes an optional index parameter to insert into the middle of an array. A table is a way to store multiple values in one variable. Lua table insert with key lua-users wiki: Tables Tutoria.