Template:CommonData/AnyFlag

The does a 'bitwise' flag compare test on a value, to see if value contains any of the test 'flags' or bit values. This is useful for testing CommonData data that might have regular flag fields. See also Template:/IsFlag. See Template: for more information and lists of other commands.


 * Usage
 * 1 - the integer number value to test
 * 2 - the integer flags value to test with
 * Returns common flags if any bits of 'flags' are in 'value', otherwise returns empty, useful in a simple '#if' test.


 * Examples

This front-end was created to shorten the wiki code needed for the bitwise idiom of 'a & b != 0', which is complicated to do in wiki code or Lua when no 'bit' library is available. Scribunto on Wikia for some reason has no 'bit' library, C or Lua or otherwise.
 * For Admins and Maintainers

Toward this issue CommonData has a custom Lua module 'Bit', in Modules:CommonData/Bit which contains 'band', 'bor' and, 'bxor', and has self contained idioms for flag checking as 'a & b == b' for must contain all bit flags in 'IsFlag', and 'a & b != 0' for must contain at least one bit flag in 'AnyFlag'. These last two functions return empty if false or 0, or the appropriate bits of 'flags', so that they can be dropped in a more simple wiki function test like '#if' without needing further '#ifeq' or '#eval'.

Callers may use the #invoke versions directly if preferred rather than this template, like '#invoke:Cd/IsFlag|band|5|3' (empty as 1 and 2 are not both in 1 and 4), '#invoke:Cd/Bit|band|5|3' (1 as 1 is in both) or '#invoke:Cd/Bit|band|5|10' (0 as 2 and 8 are not in 1 and 4).