Global LUA Functions: Difference between revisions

From SkyCorp Global
Jump to navigation Jump to search
(Created page with "All functions below are global & static: === print === === type === === setfenv === === getfenv === === rawset === === rawget === === setmetatable === === getmetatable...")
 
No edit summary
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
All functions below are global & static:
All functions below are global & static:
== Basic ==


=== print ===
=== print ===
Prints to system console (not to UI!  For that see [[MainScreen]].addGameText)


=== type ===
=== type ===
MoonSharp docs describe as:<syntaxhighlight lang="csharp">
//type (v)
//----------------------------------------------------------------------------------------------------------------
//Returns the type of its only argument, coded as a string. The possible results of this function are "nil"
//(a string, not the value nil), "number", "string", "boolean", "table", "function", "thread", and "userdata".
</syntaxhighlight>
=== assert ===
MoonSharp docs describe as:<syntaxhighlight lang="csharp">
//assert (v [, message])
//----------------------------------------------------------------------------------------------------------------
//Issues an error when the value of its argument v is false (i.e., nil or false);
//otherwise, returns all its arguments. message is an error message; when absent, it defaults to "assertion failed!"
</syntaxhighlight>
=== collectgarbage ===
MoonSharp docs describe as:<syntaxhighlight lang="csharp">
// collectgarbage  ([opt [, arg]])
// ----------------------------------------------------------------------------------------------------------------
// This function is mostly a stub towards the CLR GC. If mode is nil, "collect" or "restart", a GC is forced.
</syntaxhighlight>
=== error ===
MoonSharp docs describe as:<syntaxhighlight lang="csharp">
// error (message [, level])
// ----------------------------------------------------------------------------------------------------------------
// Terminates the last protected function called and returns message as the error message. Function error never returns.
// Usually, error adds some information about the error position at the beginning of the message.
// The level argument specifies how to get the error position.
// With level 1 (the default), the error position is where the error function was called.
// Level 2 points the error to where the function that called error was called; and so on.
// Passing a level 0 avoids the addition of error position information to the message.
</syntaxhighlight>
=== tostring ===
MoonSharp docs describe as:<syntaxhighlight lang="c#">
// tostring (v)
// ----------------------------------------------------------------------------------------------------------------
// Receives a value of any type and converts it to a string in a reasonable format. (For complete control of how
// numbers are converted, use string.format.)
//
// If the metatable of v has a "__tostring" field, then tostring calls the corresponding value with v as argument,
// and uses the result of the call as its result.
</syntaxhighlight>
=== select ===
MoonSharp docs describe as:<syntaxhighlight lang="c#">
// select (index, ...)
// -----------------------------------------------------------------------------
// If index is a number, returns all arguments after argument number index; a negative number indexes from
// the end (-1 is the last argument). Otherwise, index must be the string "#", and select returns the total
// number of extra arguments it received.
</syntaxhighlight>


=== setfenv ===
=== tonumber ===
MoonSharp docs describe as:<syntaxhighlight lang="c#">
// tonumber (e [, base])
// ----------------------------------------------------------------------------------------------------------------
// When called with no base, tonumber tries to convert its argument to a number. If the argument is already
// a number or a string convertible to a number (see §3.4.2), then tonumber returns this number; otherwise,
// it returns nil.
//
// When called with base, then e should be a string to be interpreted as an integer numeral in that base.
// 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. If the
// string e is not a valid numeral in the given base, the function returns nil.
</syntaxhighlight>


=== getfenv ===
== MetaTable ==


=== rawset ===
=== rawset ===
Line 16: Line 84:


=== 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]]

Latest revision as of 05:31, 13 July 2023

All functions below are global & static:

Basic

print

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

type

MoonSharp docs describe as:

//type (v)
//----------------------------------------------------------------------------------------------------------------
//Returns the type of its only argument, coded as a string. The possible results of this function are "nil" 
//(a string, not the value nil), "number", "string", "boolean", "table", "function", "thread", and "userdata".

assert

MoonSharp docs describe as:

//assert (v [, message])
//----------------------------------------------------------------------------------------------------------------
//Issues an error when the value of its argument v is false (i.e., nil or false); 
//otherwise, returns all its arguments. message is an error message; when absent, it defaults to "assertion failed!"

collectgarbage

MoonSharp docs describe as:

// collectgarbage  ([opt [, arg]])
// ----------------------------------------------------------------------------------------------------------------
// This function is mostly a stub towards the CLR GC. If mode is nil, "collect" or "restart", a GC is forced.

error

MoonSharp docs describe as:

// error (message [, level])
// ----------------------------------------------------------------------------------------------------------------
// Terminates the last protected function called and returns message as the error message. Function error never returns.
// Usually, error adds some information about the error position at the beginning of the message. 
// The level argument specifies how to get the error position. 
// With level 1 (the default), the error position is where the error function was called. 
// Level 2 points the error to where the function that called error was called; and so on. 
// Passing a level 0 avoids the addition of error position information to the message.

tostring

MoonSharp docs describe as:

// tostring (v)
// ----------------------------------------------------------------------------------------------------------------
// Receives a value of any type and converts it to a string in a reasonable format. (For complete control of how 
// numbers are converted, use string.format.)
// 
// If the metatable of v has a "__tostring" field, then tostring calls the corresponding value with v as argument, 
// and uses the result of the call as its result.

select

MoonSharp docs describe as:

// select (index, ...)
// -----------------------------------------------------------------------------
// If index is a number, returns all arguments after argument number index; a negative number indexes from 
// the end (-1 is the last argument). Otherwise, index must be the string "#", and select returns the total
// number of extra arguments it received.

tonumber

MoonSharp docs describe as:

// tonumber (e [, base])
// ----------------------------------------------------------------------------------------------------------------
// When called with no base, tonumber tries to convert its argument to a number. If the argument is already 
// a number or a string convertible to a number (see §3.4.2), then tonumber returns this number; otherwise, 
// it returns nil.
//
// When called with base, then e should be a string to be interpreted as an integer numeral in that base. 
// 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. If the 
// string e is not a valid numeral in the given base, the function returns nil.

MetaTable

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.