(global): Difference between revisions
No edit summary |
language stuff |
||
| Line 1: | Line 1: | ||
__NOTOC__ | __NOTOC__ | ||
<!-- GIDEROSOBJ:(global) --> | <!-- GIDEROSOBJ:(global) --> | ||
'''Supported platforms:''' [[File:Platform android.png]][[File:Platform ios.png]][[File:Platform mac.png]][[File:Platform pc.png]]<br/> | |||
'''Available since:''' Gideros 2011.6<br/> | |||
=== Description === | |||
=== | |||
Global scope of Lua environment. | Global scope of Lua environment. | ||
=== | === Example === | ||
'''Prints all current global variables:''' | '''Prints all current global variables:''' | ||
<source lang="lua"> | <source lang="lua"> | ||
| Line 20: | Line 18: | ||
globalVariable() | globalVariable() | ||
</source> | </source> | ||
{|- | {|- | ||
| style="width: 50%; vertical-align:top;"| | | style="width: 50%; vertical-align:top;"| | ||
=== | === Methods === | ||
[[ | [[assert]] ''error if v nil or false, otherwise returns v''<br/><!--GIDEROSMTD:assert(v,message) error if v nil or false, otherwise returns v--> | ||
<!-- GIDEROSMTD:assert(v,message) error if v nil or false, otherwise returns v --> | [[collectgarbage]] ''opts: stop, restart, collect, count, step, setpause, setstepmul''<br/><!--GIDEROSMTD:collectgarbage(opt,arg) opts: stop, restart, collect, count, step, setpause, setstepmul--> | ||
[[ | [[dofile]] ''executes as Lua chunk, default stdin, returns value''<br/><!--GIDEROSMTD:dofile(filename) executes as Lua chunk, default stdin, returns value--> | ||
<!-- GIDEROSMTD:collectgarbage(opt,arg) opts: stop, restart, collect, count, step, setpause, setstepmul --> | [[error]] ''terminates protected func, never returns''<br/><!--GIDEROSMTD:error(message,level) terminates protected func, never returns--> | ||
[[ | [[getfenv]] ''gets env, f can be a function or number(stack level)''<br/><!--GIDEROSMTD:getfenv(f) gets env, f can be a function or number(stack level)--> | ||
<!-- GIDEROSMTD:dofile(filename) executes as Lua chunk, default stdin, returns value --> | [[getmetatable]] ''returns metatable of given object, otherwise nil''<br/><!--GIDEROSMTD:getmetatable(object) returns metatable of given object, otherwise nil--> | ||
[[ | [[ipairs]] ''returns an iterator function, table t and 0''<br/><!--GIDEROSMTD:ipairs(t) returns an iterator function, table t and 0--> | ||
<!-- GIDEROSMTD:error(message,level) terminates protected func, never returns --> | [[loadfile]] ''loads chunk without execution, returns chunk as function, else nil plus error''<br/><!--GIDEROSMTD:loadfile(filename) loads chunk without execution, returns chunk as function, else nil plus error--> | ||
[[ | [[loadstring]] ''loads string as chunk, returns chunk as function, else nil plus error''<br/><!--GIDEROSMTD:loadstring(string,chunkname) loads string as chunk, returns chunk as function, else nil plus error--> | ||
<!-- GIDEROSMTD:getfenv(f) gets env, f can be a function or number(stack level) --> | [[next]] ''returns next index,value pair, if index=nil(default-, returns first index''<br/><!--GIDEROSMTD:next(table,index) returns next index,value pair, if index=nil(default-, returns first index--> | ||
[[ | [[pairs]] ''returns the next function and table t plus a nil, iterates over all key-value pairs''<br/><!--GIDEROSMTD:pairs(t) returns the next function and table t plus a nil, iterates over all key-value pairs--> | ||
<!-- GIDEROSMTD:getmetatable(object) returns metatable of given object, otherwise nil --> | [[pcall]] ''protected mode call, catches errors, returns status code first''<br/><!--GIDEROSMTD:pcall(f,arg1,arg2,...) protected mode call, catches errors, returns status code first--> | ||
[[ | [[print]] ''prints values to stdout using tostring''<br/><!--GIDEROSMTD:print(e1,e2,...) prints values to stdout using tostring--> | ||
<!-- GIDEROSMTD:ipairs(t) returns an iterator function, table t and 0 --> | [[rawequal]] ''non-metamethod v1==v2, returns boolean''<br/><!--GIDEROSMTD:rawequal(v1,v2) non-metamethod v1==v2, returns boolean--> | ||
[[ | [[rawget]] ''non-metamethod get value of table[index], index != nil''<br/><!--GIDEROSMTD:rawget(table,key) non-metamethod get value of table[index], index != nil--> | ||
<!-- GIDEROSMTD:loadfile(filename) loads chunk without execution, returns chunk as function, else nil plus error --> | [[rawset]] ''non-metamethod set value of table[index], index != nil''<br/><!--GIDEROSMTD:rawset(table,key,value) non-metamethod set value of table[index], index != nil--> | ||
[[ | [[require]] ''loads package, updates _LOADED, returns boolean''<br/><!--GIDEROSMTD:require(packagename) loads package, updates _LOADED, returns boolean--> | ||
<!-- GIDEROSMTD:loadstring(string,chunkname) loads string as chunk, returns chunk as function, else nil plus error --> | [[setfenv]] ''sets env, f can be a function or number(stack level, default=1-, 0=global env''<br/><!--GIDEROSMTD:setfenv(f,table) sets env, f can be a function or number(stack level, default=1-, 0=global env--> | ||
[[ | [[setmetatable]] ''sets metatable, nil to remove metatable''<br/><!--GIDEROSMTD:setmetatable(table,metatable) sets metatable, nil to remove metatable--> | ||
<!-- GIDEROSMTD:next(table,index) returns next index,value pair, if index=nil(default-, returns first index --> | [[tonumber]] ''convert to number, returns number, nil if non-convertible, 2<=base<=36''<br/><!--GIDEROSMTD:tonumber(e,base) convert to number, returns number, nil if non-convertible, 2<=base<=36--> | ||
[[ | [[tostring]] ''convert to string, returns string''<br/><!--GIDEROSMTD:tostring(e) convert to string, returns string--> | ||
<!-- GIDEROSMTD:pairs(t) returns the next function and table t plus a nil, iterates over all key-value pairs --> | [[type]] ''returns type of v as a string''<br/><!--GIDEROSMTD:type(v) returns type of v as a string--> | ||
[[ | [[unpack]] ''returns all elements from list''<br/><!--GIDEROSMTD:unpack(list) returns all elements from list--> | ||
<!-- GIDEROSMTD:pcall(f,arg1,arg2,...) protected mode call, catches errors, returns status code first --> | [[xpcall]] ''pcall function f with new error handler err''<br/><!--GIDEROSMTD:xpcall(f,err) pcall function f with new error handler err--> | ||
[[ | |||
<!-- GIDEROSMTD:print(e1,e2,...) prints values to stdout using tostring --> | |||
[[ | |||
<!-- GIDEROSMTD:rawequal(v1,v2) non-metamethod v1==v2, returns boolean --> | |||
[[ | |||
<!-- GIDEROSMTD:rawget(table,key) non-metamethod get value of table[index], index != nil --> | |||
[[ | |||
<!-- GIDEROSMTD:rawset(table,key,value) non-metamethod set value of table[index], index != nil --> | |||
[[ | |||
<!-- GIDEROSMTD:require(packagename) loads package, updates _LOADED, returns boolean --> | |||
[[ | |||
<!-- GIDEROSMTD:setfenv(f,table) sets env, f can be a function or number(stack level, default=1-, 0=global env --> | |||
[[ | |||
<!-- GIDEROSMTD:setmetatable(table,metatable) sets metatable, nil to remove metatable --> | |||
[[ | |||
<!-- GIDEROSMTD:tonumber(e,base) convert to number, returns number, nil if non-convertible, 2<=base<=36 --> | |||
[[ | |||
<!-- GIDEROSMTD:tostring(e) convert to string, returns string --> | |||
[[ | |||
<!-- GIDEROSMTD:type(v) returns type of v as a string --> | |||
[[ | |||
<!-- GIDEROSMTD:unpack(list) returns all elements from list --> | |||
[[ | |||
<!-- GIDEROSMTD:xpcall(f,err) pcall function f with new error handler err --> | |||
| style="width: 50%; vertical-align:top;"| | | style="width: 50%; vertical-align:top;"| | ||
=== | === Events === | ||
=== | === Constants === | ||
[[ | [[_G]]<br/><!--GIDEROSCST:_G--> | ||
[[ | [[_VERSION]]<br/><!--GIDEROSCST:_VERSION Lua 5.x.x--> | ||
|} | |} | ||
{{GIDEROS IMPORTANT LINKS}} | {{GIDEROS IMPORTANT LINKS}} | ||
Revision as of 22:42, 26 January 2022
Supported platforms: ![]()
![]()
![]()
![]()
Available since: Gideros 2011.6
Description
Global scope of Lua environment.
Example
Prints all current global variables:
local function globalVariable()
for k,v in pairs(_G) do
print(k,v)
end
end
globalVariable()
Methodsassert error if v nil or false, otherwise returns v |
EventsConstants |