diff options
Diffstat (limited to 'docs/classes/bitflags.html')
| -rw-r--r-- | docs/classes/bitflags.html | 305 |
1 files changed, 305 insertions, 0 deletions
diff --git a/docs/classes/bitflags.html b/docs/classes/bitflags.html new file mode 100644 index 0000000..f063149 --- /dev/null +++ b/docs/classes/bitflags.html | |||
| @@ -0,0 +1,305 @@ | |||
| 1 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" | ||
| 2 | "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> | ||
| 3 | <html> | ||
| 4 | <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> | ||
| 5 | <head> | ||
| 6 | <title>Lua-System docs</title> | ||
| 7 | <link rel="stylesheet" href="../ldoc.css" type="text/css" /> | ||
| 8 | </head> | ||
| 9 | <body> | ||
| 10 | |||
| 11 | <div id="container"> | ||
| 12 | |||
| 13 | <div id="product"> | ||
| 14 | <div id="product_logo"></div> | ||
| 15 | <div id="product_name"><big><b></b></big></div> | ||
| 16 | <div id="product_description"></div> | ||
| 17 | </div> <!-- id="product" --> | ||
| 18 | |||
| 19 | |||
| 20 | <div id="main"> | ||
| 21 | |||
| 22 | |||
| 23 | <!-- Menu --> | ||
| 24 | |||
| 25 | <div id="navigation"> | ||
| 26 | <br/> | ||
| 27 | <h1>Lua-System</h1> | ||
| 28 | |||
| 29 | |||
| 30 | <ul> | ||
| 31 | <li><a href="../index.html">Index</a></li> | ||
| 32 | </ul> | ||
| 33 | |||
| 34 | <h2>Contents</h2> | ||
| 35 | <ul> | ||
| 36 | <li><a href="#Bit_flags">Bit flags </a></li> | ||
| 37 | </ul> | ||
| 38 | |||
| 39 | |||
| 40 | <h2>Classes</h2> | ||
| 41 | <ul class="nowrap"> | ||
| 42 | <li><strong>bitflags</strong></li> | ||
| 43 | </ul> | ||
| 44 | <h2>Modules</h2> | ||
| 45 | <ul class="nowrap"> | ||
| 46 | <li><a href="../modules/system.html">system</a></li> | ||
| 47 | </ul> | ||
| 48 | <h2>Topics</h2> | ||
| 49 | <ul class=""> | ||
| 50 | <li><a href="../topics/01-introduction.md.html">1. Introduction</a></li> | ||
| 51 | <li><a href="../topics/02-development.md.html">2. Development</a></li> | ||
| 52 | <li><a href="../topics/03-terminal.md.html">3. Terminal functionality</a></li> | ||
| 53 | <li><a href="../topics/CHANGELOG.md.html">CHANGELOG</a></li> | ||
| 54 | <li><a href="../topics/LICENSE.md.html">MIT License</a></li> | ||
| 55 | </ul> | ||
| 56 | <h2>Examples</h2> | ||
| 57 | <ul class="nowrap"> | ||
| 58 | <li><a href="../examples/compat.lua.html">compat.lua</a></li> | ||
| 59 | <li><a href="../examples/flag_debugging.lua.html">flag_debugging.lua</a></li> | ||
| 60 | <li><a href="../examples/password_input.lua.html">password_input.lua</a></li> | ||
| 61 | <li><a href="../examples/read.lua.html">read.lua</a></li> | ||
| 62 | <li><a href="../examples/readline.lua.html">readline.lua</a></li> | ||
| 63 | <li><a href="../examples/spinner.lua.html">spinner.lua</a></li> | ||
| 64 | <li><a href="../examples/spiral_snake.lua.html">spiral_snake.lua</a></li> | ||
| 65 | <li><a href="../examples/terminalsize.lua.html">terminalsize.lua</a></li> | ||
| 66 | </ul> | ||
| 67 | |||
| 68 | </div> | ||
| 69 | |||
| 70 | <div id="content"> | ||
| 71 | |||
| 72 | <h1>Class <code>bitflags</code></h1> | ||
| 73 | <p>Bitflags module.</p> | ||
| 74 | <p> The bitflag object makes it easy to manipulate flags in a bitmask.</p> | ||
| 75 | |||
| 76 | <p> It has metamethods that do the hard work, adding flags sets them, substracting | ||
| 77 | unsets them. Comparing flags checks if all flags in the second set are also set | ||
| 78 | in the first set. The <code>has</code> method checks if all flags in the second set are | ||
| 79 | also set in the first set, but behaves slightly different.</p> | ||
| 80 | |||
| 81 | <p> Indexing allows checking values or setting them by bit index (eg. 0-7 for flags | ||
| 82 | in the first byte).</p> | ||
| 83 | |||
| 84 | <p> <em>NOTE</em>: unavailable flags (eg. Windows flags on a Posix system) should not be | ||
| 85 | omitted, but be assigned a value of 0. This is because the <code>has</code> method will | ||
| 86 | return <code>false</code> if the flags are checked and the value is 0.</p> | ||
| 87 | |||
| 88 | <p> See <a href="../classes/bitflags.html#system.bitflag">system.bitflag</a> (the constructor) for extensive examples on usage.</p> | ||
| 89 | |||
| 90 | |||
| 91 | <h2><a href="#Bit_flags">Bit flags </a></h2> | ||
| 92 | <table class="function_list"> | ||
| 93 | <tr> | ||
| 94 | <td class="name" nowrap><a href="#bitflag:has_all_of">bitflag:has_all_of (subset)</a></td> | ||
| 95 | <td class="summary">Checks if all the flags in the given subset are set.</td> | ||
| 96 | </tr> | ||
| 97 | <tr> | ||
| 98 | <td class="name" nowrap><a href="#bitflag:has_any_of">bitflag:has_any_of (subset)</a></td> | ||
| 99 | <td class="summary">Checks if any of the flags in the given subset are set.</td> | ||
| 100 | </tr> | ||
| 101 | <tr> | ||
| 102 | <td class="name" nowrap><a href="#bitflag:value">bitflag:value ()</a></td> | ||
| 103 | <td class="summary">Retrieves the numeric value of the bitflag object.</td> | ||
| 104 | </tr> | ||
| 105 | <tr> | ||
| 106 | <td class="name" nowrap><a href="#system.bitflag">system.bitflag ([value=0])</a></td> | ||
| 107 | <td class="summary">Creates a new bitflag object from the given value.</td> | ||
| 108 | </tr> | ||
| 109 | </table> | ||
| 110 | |||
| 111 | <br/> | ||
| 112 | <br/> | ||
| 113 | |||
| 114 | |||
| 115 | <h2 class="section-header has-description"><a name="Bit_flags"></a>Bit flags </h2> | ||
| 116 | |||
| 117 | <div class="section-description"> | ||
| 118 | Bitflag objects can be used to easily manipulate and compare bit flags. | ||
| 119 | These are primarily for use with the terminal functions, but can be used | ||
| 120 | in other places as well. | ||
| 121 | </div> | ||
| 122 | <dl class="function"> | ||
| 123 | <dt> | ||
| 124 | <a name = "bitflag:has_all_of"></a> | ||
| 125 | <strong>bitflag:has_all_of (subset)</strong> | ||
| 126 | </dt> | ||
| 127 | <dd> | ||
| 128 | Checks if all the flags in the given subset are set. | ||
| 129 | If the flags to check has a value <code>0</code>, it will always return <code>false</code>. So if there are flags that are | ||
| 130 | unsupported on a platform, they can be set to 0 and the <a href="../classes/bitflags.html#bitflag:has_all_of">has_all_of</a> function will | ||
| 131 | return <code>false</code> if the flags are checked. | ||
| 132 | |||
| 133 | |||
| 134 | <h3>Parameters:</h3> | ||
| 135 | <ul> | ||
| 136 | <li><span class="parameter">subset</span> | ||
| 137 | <span class="types"><a class="type" href="../classes/bitflags.html#system.bitflag">bitflag</a></span> | ||
| 138 | the flags to check for. | ||
| 139 | </li> | ||
| 140 | </ul> | ||
| 141 | |||
| 142 | <h3>Returns:</h3> | ||
| 143 | <ol> | ||
| 144 | |||
| 145 | <span class="types"><span class="type">boolean</span></span> | ||
| 146 | true if all the flags are set, false otherwise. | ||
| 147 | </ol> | ||
| 148 | |||
| 149 | |||
| 150 | |||
| 151 | <h3>Usage:</h3> | ||
| 152 | <ul> | ||
| 153 | <pre class="example"><span class="keyword">local</span> sys = <span class="global">require</span> <span class="string">'system'</span> | ||
| 154 | <span class="keyword">local</span> flags = sys.<span class="function-name">bitflag</span>(<span class="number">12</span>) <span class="comment">-- b1100 | ||
| 155 | </span><span class="keyword">local</span> myflags = sys.<span class="function-name">bitflag</span>(<span class="number">15</span>) <span class="comment">-- b1111 | ||
| 156 | </span><span class="global">print</span>(flags:<span class="function-name">has_all_of</span>(myflags)) <span class="comment">-- false, not all bits in myflags are set in flags | ||
| 157 | </span><span class="global">print</span>(myflags:<span class="function-name">has_all_of</span>(flags)) <span class="comment">-- true, all bits in flags are set in myflags</span></pre> | ||
| 158 | </ul> | ||
| 159 | |||
| 160 | </dd> | ||
| 161 | <dt> | ||
| 162 | <a name = "bitflag:has_any_of"></a> | ||
| 163 | <strong>bitflag:has_any_of (subset)</strong> | ||
| 164 | </dt> | ||
| 165 | <dd> | ||
| 166 | Checks if any of the flags in the given subset are set. | ||
| 167 | If the flags to check has a value <code>0</code>, it will always return <code>false</code>. So if there are flags that are | ||
| 168 | unsupported on a platform, they can be set to 0 and the <a href="../classes/bitflags.html#bitflag:has_any_of">has_any_of</a> function will | ||
| 169 | return <code>false</code> if the flags are checked. | ||
| 170 | |||
| 171 | |||
| 172 | <h3>Parameters:</h3> | ||
| 173 | <ul> | ||
| 174 | <li><span class="parameter">subset</span> | ||
| 175 | <span class="types"><a class="type" href="../classes/bitflags.html#system.bitflag">bitflag</a></span> | ||
| 176 | the flags to check for. | ||
| 177 | </li> | ||
| 178 | </ul> | ||
| 179 | |||
| 180 | <h3>Returns:</h3> | ||
| 181 | <ol> | ||
| 182 | |||
| 183 | <span class="types"><span class="type">boolean</span></span> | ||
| 184 | true if any of the flags are set, false otherwise. | ||
| 185 | </ol> | ||
| 186 | |||
| 187 | |||
| 188 | |||
| 189 | <h3>Usage:</h3> | ||
| 190 | <ul> | ||
| 191 | <pre class="example"><span class="keyword">local</span> sys = <span class="global">require</span> <span class="string">'system'</span> | ||
| 192 | <span class="keyword">local</span> flags = sys.<span class="function-name">bitflag</span>(<span class="number">12</span>) <span class="comment">-- b1100 | ||
| 193 | </span><span class="keyword">local</span> myflags = sys.<span class="function-name">bitflag</span>(<span class="number">7</span>) <span class="comment">-- b0111 | ||
| 194 | </span><span class="global">print</span>(flags:<span class="function-name">has_any_of</span>(myflags)) <span class="comment">-- true, some bits in myflags are set in flags | ||
| 195 | </span><span class="global">print</span>(myflags:<span class="function-name">has_any_of</span>(flags)) <span class="comment">-- true, some bits in flags are set in myflags</span></pre> | ||
| 196 | </ul> | ||
| 197 | |||
| 198 | </dd> | ||
| 199 | <dt> | ||
| 200 | <a name = "bitflag:value"></a> | ||
| 201 | <strong>bitflag:value ()</strong> | ||
| 202 | </dt> | ||
| 203 | <dd> | ||
| 204 | Retrieves the numeric value of the bitflag object. | ||
| 205 | |||
| 206 | |||
| 207 | |||
| 208 | <h3>Returns:</h3> | ||
| 209 | <ol> | ||
| 210 | |||
| 211 | <span class="types"><span class="type">number</span></span> | ||
| 212 | the numeric value of the bitflags. | ||
| 213 | </ol> | ||
| 214 | |||
| 215 | |||
| 216 | |||
| 217 | <h3>Usage:</h3> | ||
| 218 | <ul> | ||
| 219 | <pre class="example"><span class="keyword">local</span> sys = <span class="global">require</span> <span class="string">'system'</span> | ||
| 220 | <span class="keyword">local</span> flags = sys.<span class="function-name">bitflag</span>() <span class="comment">-- b0000 | ||
| 221 | </span>flags[<span class="number">0</span>] = <span class="keyword">true</span> <span class="comment">-- b0001 | ||
| 222 | </span>flags[<span class="number">2</span>] = <span class="keyword">true</span> <span class="comment">-- b0101 | ||
| 223 | </span><span class="global">print</span>(flags:<span class="function-name">value</span>()) <span class="comment">-- 5</span></pre> | ||
| 224 | </ul> | ||
| 225 | |||
| 226 | </dd> | ||
| 227 | <dt> | ||
| 228 | <a name = "system.bitflag"></a> | ||
| 229 | <strong>system.bitflag ([value=0])</strong> | ||
| 230 | </dt> | ||
| 231 | <dd> | ||
| 232 | Creates a new bitflag object from the given value. | ||
| 233 | |||
| 234 | |||
| 235 | <h3>Parameters:</h3> | ||
| 236 | <ul> | ||
| 237 | <li><span class="parameter">value</span> | ||
| 238 | <span class="types"><span class="type">number</span></span> | ||
| 239 | the value to create the bitflag object from. | ||
| 240 | (<em>default</em> 0) | ||
| 241 | </li> | ||
| 242 | </ul> | ||
| 243 | |||
| 244 | <h3>Returns:</h3> | ||
| 245 | <ol> | ||
| 246 | |||
| 247 | <span class="types"><a class="type" href="../classes/bitflags.html#system.bitflag">bitflag</a></span> | ||
| 248 | bitflag object with the given values set. | ||
| 249 | </ol> | ||
| 250 | |||
| 251 | |||
| 252 | |||
| 253 | <h3>Usage:</h3> | ||
| 254 | <ul> | ||
| 255 | <pre class="example"><span class="keyword">local</span> sys = <span class="global">require</span> <span class="string">'system'</span> | ||
| 256 | <span class="keyword">local</span> flags = sys.<span class="function-name">bitflag</span>(<span class="number">2</span>) <span class="comment">-- b0010 | ||
| 257 | </span> | ||
| 258 | <span class="comment">-- get state of individual bits | ||
| 259 | </span><span class="global">print</span>(flags[<span class="number">0</span>]) <span class="comment">-- false | ||
| 260 | </span><span class="global">print</span>(flags[<span class="number">1</span>]) <span class="comment">-- true | ||
| 261 | </span> | ||
| 262 | <span class="comment">-- set individual bits | ||
| 263 | </span>flags[<span class="number">0</span>] = <span class="keyword">true</span> <span class="comment">-- b0011 | ||
| 264 | </span><span class="global">print</span>(flags:<span class="function-name">value</span>()) <span class="comment">-- 3 | ||
| 265 | </span><span class="global">print</span>(flags) <span class="comment">-- "bitflags: 3" | ||
| 266 | </span> | ||
| 267 | <span class="comment">-- adding flags (bitwise OR) | ||
| 268 | </span><span class="keyword">local</span> flags1 = sys.<span class="function-name">bitflag</span>(<span class="number">1</span>) <span class="comment">-- b0001 | ||
| 269 | </span><span class="keyword">local</span> flags2 = sys.<span class="function-name">bitflag</span>(<span class="number">2</span>) <span class="comment">-- b0010 | ||
| 270 | </span><span class="keyword">local</span> flags3 = flags1 + flags2 <span class="comment">-- b0011 | ||
| 271 | </span> | ||
| 272 | <span class="comment">-- substracting flags (bitwise AND NOT) | ||
| 273 | </span><span class="global">print</span>(flags3:<span class="function-name">value</span>()) <span class="comment">-- 3 | ||
| 274 | </span>flag3 = flag3 - flag3 <span class="comment">-- b0000 | ||
| 275 | </span><span class="global">print</span>(flags3:<span class="function-name">value</span>()) <span class="comment">-- 0 | ||
| 276 | </span> | ||
| 277 | <span class="comment">-- comparing flags | ||
| 278 | </span><span class="keyword">local</span> flags4 = sys.<span class="function-name">bitflag</span>(<span class="number">7</span>) <span class="comment">-- b0111 | ||
| 279 | </span><span class="keyword">local</span> flags5 = sys.<span class="function-name">bitflag</span>(<span class="number">255</span>) <span class="comment">-- b11111111 | ||
| 280 | </span><span class="global">print</span>(flags5 ~= flags4) <span class="comment">-- true, not the same flags | ||
| 281 | </span><span class="keyword">local</span> flags6 = sys.<span class="function-name">bitflag</span>(<span class="number">7</span>) <span class="comment">-- b0111 | ||
| 282 | </span><span class="global">print</span>(flags6 == flags4) <span class="comment">-- true, same flags | ||
| 283 | </span> | ||
| 284 | <span class="comment">-- comparison of subsets | ||
| 285 | </span><span class="keyword">local</span> flags7 = sys.<span class="function-name">bitflag</span>(<span class="number">0</span>) <span class="comment">-- b0000 | ||
| 286 | </span><span class="keyword">local</span> flags8 = sys.<span class="function-name">bitflag</span>(<span class="number">3</span>) <span class="comment">-- b0011 | ||
| 287 | </span><span class="keyword">local</span> flags9 = sys.<span class="function-name">bitflag</span>(<span class="number">7</span>) <span class="comment">-- b0111 | ||
| 288 | </span><span class="global">print</span>(flags9:<span class="function-name">has_all_of</span>(flags8)) <span class="comment">-- true, flags8 bits are all set in flags9 | ||
| 289 | </span><span class="global">print</span>(flags8:<span class="function-name">has_any_of</span>(flags9)) <span class="comment">-- true, some of flags9 bits are set in flags8 | ||
| 290 | </span><span class="global">print</span>(flags8:<span class="function-name">has_all_of</span>(flags7)) <span class="comment">-- false, flags7 (== 0) is not set in flags8</span></pre> | ||
| 291 | </ul> | ||
| 292 | |||
| 293 | </dd> | ||
| 294 | </dl> | ||
| 295 | |||
| 296 | |||
| 297 | </div> <!-- id="content" --> | ||
| 298 | </div> <!-- id="main" --> | ||
| 299 | <div id="about"> | ||
| 300 | <i>generated by <a href="http://github.com/lunarmodules/LDoc">LDoc 1.5.0</a></i> | ||
| 301 | <i style="float:right;">Last updated 2024-06-20 23:11:37 </i> | ||
| 302 | </div> <!-- id="about" --> | ||
| 303 | </div> <!-- id="container" --> | ||
| 304 | </body> | ||
| 305 | </html> | ||
