Help with your scripting

Standard Lua 5.1 Commands that work in Skyline

Standard Lua 5.1 Commands that work in Skyline

Postby Shando » 21 Mar 2015, 14:41

Hi All,

This thread is for Users to add standard Lua 5.1 commands that work in Skyline (as a supplement to the API docs). The Lua 5.1 API docs can be found here http://www.lua.org/manual/5.1/manual.html.

If a command isn't listed in this thread, it doesn't mean you can't use it, it just means that no-one has tested it in Skyline yet!

Table
Code: Select all
table.concat (table [, sep [, i [, j]]])
table.insert (table, [pos,] value)
table.maxn (table)
table.remove (table [, pos])
table.sort (table [, comp])
# ( tTemp ) or table.getn ( tTemp ) - NB: table.getn has been deprecated in Lua 5.1


String
Code: Select all
string.byte (s [, i [, j]])
string.char (•••)
string.find (s, pattern [, init [, plain]])
string.format (formatstring, •••)
string.gmatch (s, pattern)
string.gsub (s, pattern, repl [, n])
string.len (s)
string.lower (s)
string.match (s, pattern [, init])
string.rep (s, n)
string.reverse (s)
string.sub (s, i [, j])
string.upper (s)


Operating System
Code: Select all
os.time ([table])


Input/Output
Code: Select all
io.open (filename [, mode])
io.close ([file])
io.read (···)


Other
Code: Select all
type ( typeToTestFor ) - see NOTE1 below
debug.getinfo ( level ) - see NOTE2 below
tonumber ( value ) - see NOTE3 below
ipairs ( table ) - see NOTE4 below
pairs ( table ) - see NOTE5 below


NOTE1: There are eight basic types in Lua: nil, boolean, number, string, userdata, function, thread, and table. The type function gives the type name of a given value:

Code: Select all
sky.lprint(type("Hello world"));  --> string
sky.lprint(type(10.4*3));         --> number
sky.lprint(type(sky.lprint));     --> function
sky.lprint(type(type));           --> function
sky.lprint(type(true));           --> boolean
sky.lprint(type(nil));            --> nil
sky.lprint(type(type(X)));        --> string


NOTE2: I have only tested this as follows:

Code: Select all
local line = debug.getinfo(1).currentline


which does indeed return the line number in the script file (NB: this was an EXTERNAL script file NOT a microscript).

For more information on the Debug commands, see here:

http://www.lua.org/manual/5.1/manual.html#3.8

NOTE3: This tries to convert its argument to a number. If the argument is already a number or a string convertible to a number, then tonumber returns this number; otherwise, it returns nil.

There is also an optional argument that specifies the base to interpret the number. The base may be any integer between 2 and 36, inclusive. In bases above 10, the letter 'A' (in either upper or lower case) represents 10, 'B' represents 11, and so forth, with 'Z' representing 35. In base 10 (the default), the number can have a decimal part, as well as an optional exponent part (see §2.1 of the Lua Manual). In other bases, only unsigned integers are accepted. (NB: I have NOT tried the base argument)

NOTE4: Returns three values: an iterator function, the table, and 0, so that the construction

Code: Select all
for i, v in ipairs ( table ) do
-- body of code
end


will iterate over the key/value pairs (1, table[1]), (2, table[2]), ···, up to the first integer key absent from the Table.

NOTE5: This returns three values: the next function, the table, and nil, so that the construction

Code: Select all
for k, v in pairs ( table ) do
-- body of code
end


will iterate over ALL key–value pairs of the Table.

The main difference between ipairs and pairs is that pairs will traverse ALL key/value pairs in a Table, whereas ipairs will ONLY traverse the Table until it finds the first NON-INTEGER key.

For more information on the "Other" list of possible functions, please see here:

http://www.lua.org/manual/5.1/manual.html#5.1
Last edited by Shando on 26 Apr 2015, 03:20, edited 4 times in total.
Reason: Fixed minor typos
Alienware 17 (i7-4700MQ 2.4GHz 16GB GTX770M Win 10 64)

Love, Hope, Strength http://www.lovehopestrength.co.uk
User avatar
Shando
Skyline Moderator
Skyline Moderator
 
Posts: 480
Joined: 06 Mar 2013, 22:35
Location: Kings Beach, Queensland
Skill: Programmer
Skill: Scripter
Skill: Level Designer

Return to Lua Scripting

Who is online

Users browsing this forum: No registered users and 2 guests