Difference between revisions of "Global LUA Functions"

From SkyCorp Global
(print)
Line 17: Line 17:
  
 
=== getmetatable ===
 
=== getmetatable ===
 +
 +
== Table Iterators ==
 +
 +
=== ipairs ===
 +
MoonSharp docs describe as:<syntaxhighlight lang="csharp">
 +
// ipairs (t)
 +
// -------------------------------------------------------------------------------------------------------------------
 +
// If t has a metamethod __ipairs, calls it with t as argument and returns the first three results from the call.
 +
// Otherwise, returns three values: an iterator function, the table t, and 0, so that the construction
 +
//   for i,v in ipairs(t) do body end
 +
// will iterate over the pairs (1,t[1]), (2,t[2]), ..., up to the first integer key absent from the table.
 +
</syntaxhighlight>
 +
 +
=== pairs ===
 +
MoonSharp docs describe as:<syntaxhighlight lang="csharp">
 +
// pairs (t)
 +
// -------------------------------------------------------------------------------------------------------------------
 +
// If t has a metamethod __pairs, calls it with t as argument and returns the first three results from the call.
 +
// Otherwise, returns three values: the next function, the table t, and nil, so that the construction
 +
//    for k,v in pairs(t) do body end
 +
// will iterate over all key–value pairs of table t.
 +
// See function next for the caveats of modifying the table during its traversal.
 +
</syntaxhighlight>
 +
 +
=== next ===
 +
MoonSharp docs describe as:<syntaxhighlight lang="csharp">
 +
// next (table [, index])
 +
// -------------------------------------------------------------------------------------------------------------------
 +
// Allows a program to traverse all fields of a table. Its first argument is a table and its second argument is an
 +
// index in this table. next returns the next index of the table and its associated value.
 +
// When called with nil as its second argument, next returns an initial index and its associated value.
 +
// When called with the last index, or with nil in an empty table, next returns nil. If the second argument is absent,
 +
// then it is interpreted as nil. In particular, you can use next(t) to check whether a table is empty.
 +
// The order in which the indices are enumerated is not specified, even for numeric indices.
 +
// (To traverse a table in numeric order, use a numerical for.)
 +
// The behavior of next is undefined if, during the traversal, you assign any value to a non-existent field in the table.
 +
// You may however modify existing fields. In particular, you may clear existing fields.
 +
</syntaxhighlight>
 
[[Category:LUA Class Reference]]
 
[[Category:LUA Class Reference]]

Revision as of 05:21, 13 July 2023

All functions below are global & static:

print

Prints to system console (not to UI! For that see MainScreen.addGameText)

type

setfenv

getfenv

rawset

rawget

setmetatable

getmetatable

Table Iterators

ipairs

MoonSharp docs describe as:

// ipairs (t)
// -------------------------------------------------------------------------------------------------------------------
// If t has a metamethod __ipairs, calls it with t as argument and returns the first three results from the call.
// Otherwise, returns three values: an iterator function, the table t, and 0, so that the construction
//	  for i,v in ipairs(t) do body end
// will iterate over the pairs (1,t[1]), (2,t[2]), ..., up to the first integer key absent from the table.

pairs

MoonSharp docs describe as:

// pairs (t)
// -------------------------------------------------------------------------------------------------------------------
// If t has a metamethod __pairs, calls it with t as argument and returns the first three results from the call.
// Otherwise, returns three values: the next function, the table t, and nil, so that the construction
//     for k,v in pairs(t) do body end
// will iterate over all key–value pairs of table t.
// See function next for the caveats of modifying the table during its traversal.

next

MoonSharp docs describe as:

// next (table [, index])
// -------------------------------------------------------------------------------------------------------------------
// Allows a program to traverse all fields of a table. Its first argument is a table and its second argument is an 
// index in this table. next returns the next index of the table and its associated value. 
// When called with nil as its second argument, next returns an initial index and its associated value. 
// When called with the last index, or with nil in an empty table, next returns nil. If the second argument is absent, 
// then it is interpreted as nil. In particular, you can use next(t) to check whether a table is empty.
// The order in which the indices are enumerated is not specified, even for numeric indices. 
// (To traverse a table in numeric order, use a numerical for.)
// The behavior of next is undefined if, during the traversal, you assign any value to a non-existent field in the table. 
// You may however modify existing fields. In particular, you may clear existing fields.