Difference between revisions of "Rawset"
From GiderosMobile
| (3 intermediate revisions by 2 users not shown) | |||
| Line 1: | Line 1: | ||
__NOTOC__ | __NOTOC__ | ||
| − | + | '''Available since:''' Gideros 2011.6<br/> | |
| − | ''' | + | '''Class:''' [[(global)]]<br/> |
| − | ''' | ||
| − | === | + | === Description === |
| − | + | Sets the real value of table[index] to value, without invoking any metamethod. table must be a table, index any value different from nil, and value any Lua value. | |
| + | <syntaxhighlight lang="lua"> | ||
| + | (table) = rawset(table,key,value) | ||
| + | </syntaxhighlight> | ||
| − | + | === Parameters === | |
| − | < | + | '''table''': (table) table to set the value to <br/> |
| − | (table | + | '''key''': (any) key of the table to set the value to <br/> |
| − | </ | + | '''value''': (any) value to store in the table <br/> |
| + | |||
| + | === Return values === | ||
| + | '''Returns''' (table) provided table<br/> | ||
| − | === | + | === Example === |
| − | ''' | + | '''Generate variable names''' |
| − | + | <syntaxhighlight lang="lua"> | |
| − | + | for i = 1, 10 do | |
| + | rawset(_G, "item"..i, "I am "..i) | ||
| + | end | ||
| + | print(item1) -- I am 1 | ||
| + | print(item2) -- I am 2 | ||
| + | print(item3) -- I am 3 | ||
| + | -- ... | ||
| + | </syntaxhighlight> | ||
| − | === | + | === See also === |
| − | ''' | + | '''https://luau.org/library#global-functions'''<br/> |
{{(global)}} | {{(global)}} | ||
Latest revision as of 11:23, 21 July 2025
Available since: Gideros 2011.6
Class: (global)
Description
Sets the real value of table[index] to value, without invoking any metamethod. table must be a table, index any value different from nil, and value any Lua value.
(table) = rawset(table,key,value)
Parameters
table: (table) table to set the value to
key: (any) key of the table to set the value to
value: (any) value to store in the table
Return values
Returns (table) provided table
Example
Generate variable names
for i = 1, 10 do
rawset(_G, "item"..i, "I am "..i)
end
print(item1) -- I am 1
print(item2) -- I am 2
print(item3) -- I am 3
-- ...
See also
https://luau.org/library#global-functions