Skip to content

Commit

Permalink
Merge pull request orbitersim#427 from TheGondos/luavessel
Browse files Browse the repository at this point in the history
Update lua capabilities
  • Loading branch information
jarmonik authored Mar 18, 2024
2 parents 7c0717a + a64b401 commit 5048798
Show file tree
Hide file tree
Showing 117 changed files with 22,962 additions and 433 deletions.
22 changes: 20 additions & 2 deletions Html/Main/Script/Datatypes.htm
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,13 @@ <h3>Vectors</h3>
V1 = {x=1,y=0,z=-1}<br>
V2 = {}; V2.x=0; V2.y=1.1; V2.z=-16<br>
V3 = {}; V3["x"]=15; V3["y"]=-3.145; V3["z"]=1e3
</div></p>
</div>
<p>To provide an easier path when migrating from C++ to Lua, a _V(x, y, z) function is also available to create vectors.
Since this adds a level of indirection, you should avoid using this syntax in tight loops.
<div class="code">
V1 = _V(1, 0, -1)
</div>
</p>

<h4>See also:</h4>
<p>
Expand All @@ -67,7 +73,19 @@ <h3>Matrices</h3>
M2 = {}; M2.m11=1; M2.m12=0; M2.m13=0; M2.m21=0; M2.m22=1; M2.m23=0; M2.m31=0; M2.m32=0; M2.m33=1<br>
M3 = {}; M3["m11"]=1; M3["m12"]=0; M3["m13"]=0; M3["m21"]=0; M3["m22"]=1; M3["m23"]=0; M3["m31"]=0; M3["m32"]=0; M3["m33"]=1;
</div></p>

<p>
To provide an easier path when migrating from C++ to Lua, an _M(...) function is also available to create matrices.
Since this adds a level of indirection, you should avoid using this syntax in tight loops.
<div class="code">
local sinc = math.sin(tgt.inc)</br>
local cinc = math.cos(tgt.inc)</br>
local slan = math.sin(tgt.lan)</br>
local clan = math.cos(tgt.lan)</br>
</br>
local R1 = _M(1,0,0, 0,cinc,sinc, 0,-sinc,cinc)</br>
local R2 = _M(clan,0,-slan, 0,1,0, slan,0,clan)
</div>
</p>
<h4>See also:</h4>
<p>
<a href="api_vec.htm">Vector and matrix operations</a>,
Expand Down
1 change: 1 addition & 0 deletions Html/Main/Script/ScriptRef.htm
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ <h3>Script reference</h3>
<li><a href="api_proc.htm">proc: Script process control</a></li>
<li><a href="api_oapi.htm">oapi: General Orbiter API functions</a></li>
<li><a href="api_vessel.htm">vessel: Vessel access functions</a></li>
<li><a href="api_bit.htm">bit: bit manipulation library</a></li>
</ul>
<li><a href="function.htm">Class methods</a></li>
<ul>
Expand Down
156 changes: 156 additions & 0 deletions Html/Main/Script/api_bit.htm
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" Content="text-html; charset=Windows-1252">
<LINK REL="stylesheet" HREF="../Orbiter.css" TYPE="TEXT/CSS" />
<LINK REL="stylesheet" HREF="OrbiterAPI.css" TYPE="TEXT/CSS">
<title>Script API: bit (Bit manipulation functions)</title>
</HEAD>
<BODY BGCOLOR=#FFFFFF TEXT=#000000>

<p class="header"><a href="intro.htm">Orbiter</a> &gt; <a href="ScriptRef.htm">Script</a> &gt; <a href="function.htm">Functions</a> &gt; bit</p>

<h1>bit: Bit manipulation functions</h1>
<p>The <i>bit</i> library contains some general functions to manipulate bits and bitfields.
Bitfields are based on Lua numbers and are limited to 32 bits (constrained by the precision of Lua numbers defined as 64bit floating points)</p>

<table class="summary" cols=2>
<tr>
<td><a href="#bit_anyset">bit.anyset</a></td>
<td>Test if a bitfield contains at least one bit from a mask.</td>
</tr>
<tr>
<td><a href="#bit_allset">bit.allset</a></td>
<td>Test if a bitfield contains all bits from a mask.</td>
</tr>
<tr>
<td><a href="#bit_and">bit.band</a></td>
<td>Compute the logical and between two bitfields.</td>
</tr>
<tr>
<td><a href="#bit_or">bit.bor</a></td>
<td>Compute the logical or between two bitfields.</td>
</tr>
<tr>
<td><a href="#bit_not">bit.bnot</a></td>
<td>Compute the logical not of a bitfield.</td>
</tr>
<tr>
<td><a href="#bit_mask">bit.mask</a></td>
<td>Compute the value of a masked bitfield.</td>
</tr>
</table>
<h4>Notes:</h4>
<p>Since <i>and</i>, <i>or</i> and <i>not</i> are reserved keywords in Lua, the functions are named <i>band</i>, <i>bor</i> and <i>bnot</i></p>
<p>The pseudocode in the following definitions is using C notation for logical operations</p>


<div class="func_block">

<div class="func"><a name="bit_anyset"></a>
<h3>v = bit.anyset(value, mask)</h3>
<p>Test if a bitfield contains at least one bit from a mask.</p>

<h4>Parameters:</h4>
<table>
<tr><td>value&nbsp;(number):</td><td>value to test</td></tr>
<tr><td>mask&nbsp;(number):</td><td>mask</td></tr>
</table>

<h4>Return values:</h4>
<table>
<tr><td>v&nbsp;(boolean):</td><td>(value & mask) != 0</td></tr>
</table>

</div>


<div class="func"><a name="bit_allset"></a>
<h3>v = bit.allset(value, mask)<br></h3>
<p>Test if a bitfield contains all bits from a mask.</p>

<h4>Parameters:</h4>
<table>
<tr><td>value&nbsp;(number):</td><td>value to test</td></tr>
<tr><td>mask&nbsp;(number):</td><td>mask</td></tr>
</table>

<h4>Return values:</h4>
<table>
<tr><td>v&nbsp;(boolean):</td><td>(value & mask) == mask</td></tr>
</table>
</div>


<div class="func"><a name="bit_and"></a>
<h3>v = bit.band(a,b)<br></h3>
<p>Returns the logical and of two values.</p>

<h4>Parameters:</h4>
<table>
<tr><td>a&nbsp;(number):</td><td>first operand</td></tr>
<tr><td>b&nbsp;(number):</td><td>second operand</td></tr>
</table>

<h4>Return values:</h4>
<table>
<tr><td>v&nbsp;(number):</td><td>result of a & b</td></tr>
</table>
</div>


<div class="func"><a name="bit_or"></a>
<h3>v = bit.bor(a,b, ...)<br></h3>
<p>Returns the logical or of two or more values.</p>

<h4>Parameters:</h4>
<table>
<tr><td>a&nbsp;(number):</td><td>first operand</td></tr>
<tr><td>b&nbsp;(number):</td><td>second operand</td></tr>
<tr><td>...&nbsp;(numbers):</td><td>additional operands</td></tr>
</table>

<h4>Return values:</h4>
<table>
<tr><td>v&nbsp;(number):</td><td>result of a | b | ...</td></tr>
</table>
<h4>Note:</h4>
<p>If you know for certain that a and b have no overlapping bits set, you can use an addition to simulate an or operation<p>
</div>


<div class="func"><a name="bit_not"></a>
<h3>v = bit.bnot(a)<br></h3>
<p>Returns the logical not of a value.</p>

<h4>Parameters:</h4>
<table>
<tr><td>a&nbsp;(number):</td><td>operand</td></tr>
</table>

<h4>Return values:</h4>
<table>
<tr><td>v&nbsp;(number):</td><td>result of ~a</td></tr>
</table>
</div>


<div class="func"><a name="bit_mask"></a>
<h3>v = bit.mask(bitfield, mask)<br></h3>
<p>Compute the value of a masked bitfield.</p>

<h4>Parameters:</h4>
<table>
<tr><td>bitfield&nbsp;(number):</td><td>bitfield to mask</td></tr>
<tr><td>mask&nbsp;(number):</td><td>mask</td></tr>
</table>

<h4>Return value:</h4>
<table>
<tr><td>v&nbsp;(number):</td><td>result of bitfield & ~mask</td></tr>
</table>
</div>

</div>
</BODY>
</HTML>
Loading

0 comments on commit 5048798

Please sign in to comment.