BitReplace: Difference between revisions
Jump to navigation
Jump to search
(Created page with "{{Server client function}} {{Needs_Example}} __NOTOC__ {{New feature/item|3.0132|1.3.2|5340| ... }} ==Syntax== <syntaxhighlight lang="lua"> uint bitReplace ( uint var, uint replaceValue, int f...") |
(Mark optional params in syntax and add optional params section) |
||
(2 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
{{Server client function}} | {{Server client function}} | ||
__NOTOC__ | __NOTOC__ | ||
{{New feature/item|3.0132|1.3.2|5340| | {{New feature/item|3.0132|1.3.2|5340| | ||
This function returns the unsigned number formed by var value with replacement specified at bits field to field + width - 1 | |||
}} | }} | ||
==Syntax== | ==Syntax== | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
uint bitReplace ( uint var, uint replaceValue, int field, int width = 1 ) | uint bitReplace(uint var, uint replaceValue, int field [, int width = 1]) | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Line 15: | Line 14: | ||
*'''replaceValue:''' The replaceValue | *'''replaceValue:''' The replaceValue | ||
*'''field:''' The field number | *'''field:''' The field number | ||
===Optional Arguments=== | |||
{{OptionalArg}} | |||
*'''width:''' Number of bits to extract | *'''width:''' Number of bits to extract | ||
Latest revision as of 13:27, 5 August 2021
This function returns the unsigned number formed by var value with replacement specified at bits field to field + width - 1
Syntax
uint bitReplace(uint var, uint replaceValue, int field [, int width = 1])
Required arguments
- var: The value
- replaceValue: The replaceValue
- field: The field number
Optional Arguments
NOTE: When using optional arguments, you might need to supply all arguments before the one you wish to use. For more information on optional arguments, see optional arguments.
- width: Number of bits to extract
Returns
Returns the replaced value/bit sequence.
Example
function replaceColorAlpha(color, alpha) return bitReplace(color,alpha,24,8) -- return value with replaced bits 24-32 ( the alpha, http://en.wikipedia.org/wiki/RGBA_color_space ) end