Refactor how lua bindings work

This commit is contained in:
James Lambert 2022-12-18 16:40:43 -07:00
parent 9b7077aa09
commit f3e63ecbc7
26 changed files with 1782 additions and 261 deletions

View file

@ -31,8 +31,12 @@
<h2>Modules</h2>
<ul class="nowrap">
<li><a href="modules/LuaScene.html">LuaScene</a></li>
<li><a href="modules/vector3.html">vector3</a></li>
<li><a href="modules/sk_input.html">sk_input</a></li>
<li><a href="modules/LuaMesh.html">LuaMesh</a></li>
<li><a href="modules/sk_transform.html">sk_transform</a></li>
<li><a href="modules/sk_definition_writer.html">sk_definition_writer</a></li>
<li><a href="modules/sk_math.html">sk_math</a></li>
<li><a href="modules/sk_scene.html">sk_scene</a></li>
</ul>
</div>
@ -44,11 +48,27 @@
<h2>Modules</h2>
<table class="module_list">
<tr>
<td class="name" nowrap><a href="modules/LuaScene.html">LuaScene</a></td>
<td class="summary">Scene functions</td>
<td class="name" nowrap><a href="modules/sk_input.html">sk_input</a></td>
<td class="summary"></td>
</tr>
<tr>
<td class="name" nowrap><a href="modules/vector3.html">vector3</a></td>
<td class="name" nowrap><a href="modules/LuaMesh.html">LuaMesh</a></td>
<td class="summary"></td>
</tr>
<tr>
<td class="name" nowrap><a href="modules/sk_transform.html">sk_transform</a></td>
<td class="summary"></td>
</tr>
<tr>
<td class="name" nowrap><a href="modules/sk_definition_writer.html">sk_definition_writer</a></td>
<td class="summary"></td>
</tr>
<tr>
<td class="name" nowrap><a href="modules/sk_math.html">sk_math</a></td>
<td class="summary"></td>
</tr>
<tr>
<td class="name" nowrap><a href="modules/sk_scene.html">sk_scene</a></td>
<td class="summary"></td>
</tr>
</table>
@ -57,7 +77,7 @@
</div> <!-- id="main" -->
<div id="about">
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.6</a></i>
<i style="float:right;">Last updated 2022-10-01 11:25:20 </i>
<i style="float:right;">Last updated 2022-12-18 16:40:03 </i>
</div> <!-- id="about" -->
</div> <!-- id="container" -->
</body>

View file

@ -38,15 +38,19 @@
<h2>Modules</h2>
<ul class="nowrap">
<li><a href="../modules/LuaScene.html">LuaScene</a></li>
<li><strong>vector3</strong></li>
<li><a href="../modules/sk_input.html">sk_input</a></li>
<li><strong>LuaMesh</strong></li>
<li><a href="../modules/sk_transform.html">sk_transform</a></li>
<li><a href="../modules/sk_definition_writer.html">sk_definition_writer</a></li>
<li><a href="../modules/sk_math.html">sk_math</a></li>
<li><a href="../modules/sk_scene.html">sk_scene</a></li>
</ul>
</div>
<div id="content">
<h1>Module <code>vector3</code></h1>
<h1>Module <code>LuaMesh</code></h1>
<p></p>
<p></p>
@ -54,8 +58,8 @@
<h2><a href="#Functions">Functions</a></h2>
<table class="function_list">
<tr>
<td class="name" nowrap><a href="#vector3">vector3 (x, y, z)</a></td>
<td class="summary">creates a new 3d vector</td>
<td class="name" nowrap><a href="#generate_mesh">generate_mesh (renderChunks, file[, changes])</a></td>
<td class="summary">Generates a mesh</td>
</tr>
</table>
@ -67,23 +71,27 @@
<dl class="function">
<dt>
<a name = "vector3"></a>
<strong>vector3 (x, y, z)</strong>
<a name = "generate_mesh"></a>
<strong>generate_mesh (renderChunks, file[, changes])</strong>
</dt>
<dd>
creates a new 3d vector
Generates a mesh
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">x</span>
the x value for the vector
<li><span class="parameter">renderChunks</span>
<span class="types"><span class="type">{RenderChunk,...}</span></span>
</li>
<li><span class="parameter">y</span>
the x value for the vector
<li><span class="parameter">file</span>
<span class="types"><a class="type" href="https://www.lua.org/manual/5.1/manual.html#5.4">string</a></span>
suffix where the mesh definition is written to
</li>
<li><span class="parameter">z</span>
the x value for the vector
<li><span class="parameter">changes</span>
<span class="types"><span class="type">DisplayListOverrides</span></span>
to the display list
(<em>optional</em>)
</li>
</ul>
@ -99,7 +107,7 @@
</div> <!-- id="main" -->
<div id="about">
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.6</a></i>
<i style="float:right;">Last updated 2022-10-01 11:25:20 </i>
<i style="float:right;">Last updated 2022-12-18 16:40:03 </i>
</div> <!-- id="about" -->
</div> <!-- id="container" -->
</body>

View file

@ -0,0 +1,488 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<head>
<title>Reference</title>
<link rel="stylesheet" href="../ldoc.css" type="text/css" />
</head>
<body>
<div id="container">
<div id="product">
<div id="product_logo"></div>
<div id="product_name"><big><b></b></big></div>
<div id="product_description"></div>
</div> <!-- id="product" -->
<div id="main">
<!-- Menu -->
<div id="navigation">
<br/>
<h1>skeletool64</h1>
<ul>
<li><a href="../index.html">Index</a></li>
</ul>
<h2>Contents</h2>
<ul>
<li><a href="#Functions">Functions</a></li>
<li><a href="#Tables">Tables</a></li>
</ul>
<h2>Modules</h2>
<ul class="nowrap">
<li><a href="../modules/sk_input.html">sk_input</a></li>
<li><a href="../modules/LuaMesh.html">LuaMesh</a></li>
<li><a href="../modules/sk_transform.html">sk_transform</a></li>
<li><strong>sk_definition_writer</strong></li>
<li><a href="../modules/sk_math.html">sk_math</a></li>
<li><a href="../modules/sk_scene.html">sk_scene</a></li>
</ul>
</div>
<div id="content">
<h1>Module <code>sk_definition_writer</code></h1>
<p></p>
<p></p>
<h2><a href="#Functions">Functions</a></h2>
<table class="function_list">
<tr>
<td class="name" nowrap><a href="#reference_to">reference_to (value[, index])</a></td>
<td class="summary">creates a pointer to another piece of data
the data being referenced must be added to the output
via add_definition</td>
</tr>
<tr>
<td class="name" nowrap><a href="#is_reference_type">is_reference_type (value)</a></td>
<td class="summary">returns true if value is a reference</td>
</tr>
<tr>
<td class="name" nowrap><a href="#raw">raw (value)</a></td>
<td class="summary">renders a string directly in the ouptut instead of wrapping the output in quotes</td>
</tr>
<tr>
<td class="name" nowrap><a href="#is_raw">is_raw (value)</a></td>
<td class="summary">returns true if value is a RawType</td>
</tr>
<tr>
<td class="name" nowrap><a href="#macro">macro (name, ...)</a></td>
<td class="summary">Generates as a macro eg `macro("MACRO_NAME", 1, 2)` will be displayed as
MACRO_NAME(1, 2) in the c file output</td>
</tr>
<tr>
<td class="name" nowrap><a href="#is_macro">is_macro (value)</a></td>
<td class="summary">Returns true if value is of type MacroType</td>
</tr>
<tr>
<td class="name" nowrap><a href="#add_definition">add_definition (nameHint, dataType, location, data)</a></td>
<td class="summary">Outputs a c file defintion</td>
</tr>
<tr>
<td class="name" nowrap><a href="#consume_pending_definitions">consume_pending_definitions ()</a></td>
<td class="summary">Returns and clears all definitions that have been created using add_definiton
meant for use in the c code</td>
</tr>
<tr>
<td class="name" nowrap><a href="#process_definitions">process_definitions (definitions)</a></td>
<td class="summary">Processes definitions correctly connecting references
meant for use in the c code</td>
</tr>
</table>
<h2><a href="#Tables">Tables</a></h2>
<table class="function_list">
<tr>
<td class="name" nowrap><a href="#RefType">RefType</a></td>
<td class="summary"></td>
</tr>
<tr>
<td class="name" nowrap><a href="#RawType">RawType</a></td>
<td class="summary"></td>
</tr>
<tr>
<td class="name" nowrap><a href="#null_value">null_value</a></td>
<td class="summary">alias for raw("NULL")</td>
</tr>
<tr>
<td class="name" nowrap><a href="#MacroType">MacroType</a></td>
<td class="summary"></td>
</tr>
<tr>
<td class="name" nowrap><a href="#PendingDefinition">PendingDefinition</a></td>
<td class="summary"></td>
</tr>
</table>
<br/>
<br/>
<h2 class="section-header "><a name="Functions"></a>Functions</h2>
<dl class="function">
<dt>
<a name = "reference_to"></a>
<strong>reference_to (value[, index])</strong>
</dt>
<dd>
creates a pointer to another piece of data
the data being referenced must be added to the output
via add_definition
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">value</span>
<span class="types"><span class="type">any</span></span>
the value to reference
</li>
<li><span class="parameter">index</span>
<span class="types"><span class="type">integer</span></span>
if value is an array, you can specify the element to reference using this index
(<em>optional</em>)
</li>
</ul>
<h3>Returns:</h3>
<ol>
<span class="types"><a class="type" href="../modules/sk_definition_writer.html#RefType">RefType</a></span>
result
</ol>
</dd>
<dt>
<a name = "is_reference_type"></a>
<strong>is_reference_type (value)</strong>
</dt>
<dd>
returns true if value is a reference
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">value</span>
<span class="types"><span class="type">any</span></span>
any
</li>
</ul>
<h3>Returns:</h3>
<ol>
<span class="types"><span class="type">boolean</span></span>
result
</ol>
</dd>
<dt>
<a name = "raw"></a>
<strong>raw (value)</strong>
</dt>
<dd>
renders a string directly in the ouptut instead of wrapping the output in quotes
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">value</span>
<span class="types"><a class="type" href="https://www.lua.org/manual/5.1/manual.html#5.4">string</a></span>
</li>
</ul>
<h3>Returns:</h3>
<ol>
<span class="types"><a class="type" href="../modules/sk_definition_writer.html#RawType">RawType</a></span>
result
</ol>
</dd>
<dt>
<a name = "is_raw"></a>
<strong>is_raw (value)</strong>
</dt>
<dd>
returns true if value is a RawType
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">value</span>
<span class="types"><span class="type">any</span></span>
</li>
</ul>
<h3>Returns:</h3>
<ol>
<span class="types"><span class="type">boolean</span></span>
result
</ol>
</dd>
<dt>
<a name = "macro"></a>
<strong>macro (name, ...)</strong>
</dt>
<dd>
Generates as a macro eg `macro("MACRO_NAME", 1, 2)` will be displayed as
MACRO_NAME(1, 2) in the c file output
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">name</span>
<span class="types"><a class="type" href="https://www.lua.org/manual/5.1/manual.html#5.4">string</a></span>
</li>
<li><span class="parameter">...</span>
<span class="types"><span class="type">{any,...}</span></span>
</li>
</ul>
<h3>Returns:</h3>
<ol>
<span class="types"><a class="type" href="../modules/sk_definition_writer.html#MacroType">MacroType</a></span>
result
</ol>
</dd>
<dt>
<a name = "is_macro"></a>
<strong>is_macro (value)</strong>
</dt>
<dd>
Returns true if value is of type MacroType
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">value</span>
<span class="types"><span class="type">any</span></span>
</li>
</ul>
<h3>Returns:</h3>
<ol>
<span class="types"><span class="type">boolean</span></span>
</ol>
</dd>
<dt>
<a name = "add_definition"></a>
<strong>add_definition (nameHint, dataType, location, data)</strong>
</dt>
<dd>
Outputs a c file defintion
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">nameHint</span>
<span class="types"><a class="type" href="https://www.lua.org/manual/5.1/manual.html#5.4">string</a></span>
</li>
<li><span class="parameter">dataType</span>
<span class="types"><a class="type" href="https://www.lua.org/manual/5.1/manual.html#5.4">string</a></span>
the c type the definition is, if it is an array it should end in []
</li>
<li><span class="parameter">location</span>
<span class="types"><a class="type" href="https://www.lua.org/manual/5.1/manual.html#5.4">string</a></span>
the file suffix where this definiton should be located in
</li>
<li><span class="parameter">data</span>
<span class="types"><span class="type">any</span></span>
The data of the file definition
</li>
</ul>
</dd>
<dt>
<a name = "consume_pending_definitions"></a>
<strong>consume_pending_definitions ()</strong>
</dt>
<dd>
Returns and clears all definitions that have been created using add_definiton
meant for use in the c code
<h3>Returns:</h3>
<ol>
<span class="types"><a class="type" href="../modules/sk_definition_writer.html#PendingDefinition">{PendingDefinition,...}</a></span>
result
</ol>
</dd>
<dt>
<a name = "process_definitions"></a>
<strong>process_definitions (definitions)</strong>
</dt>
<dd>
Processes definitions correctly connecting references
meant for use in the c code
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">definitions</span>
<span class="types"><a class="type" href="../modules/sk_definition_writer.html#PendingDefinition">{PendingDefinition,...}</a></span>
</li>
</ul>
</dd>
</dl>
<h2 class="section-header "><a name="Tables"></a>Tables</h2>
<dl class="function">
<dt>
<a name = "RefType"></a>
<strong>RefType</strong>
</dt>
<dd>
</dd>
<dt>
<a name = "RawType"></a>
<strong>RawType</strong>
</dt>
<dd>
</dd>
<dt>
<a name = "null_value"></a>
<strong>null_value</strong>
</dt>
<dd>
alias for raw("NULL")
</dd>
<dt>
<a name = "MacroType"></a>
<strong>MacroType</strong>
</dt>
<dd>
</dd>
<dt>
<a name = "PendingDefinition"></a>
<strong>PendingDefinition</strong>
</dt>
<dd>
<h3>Fields:</h3>
<ul>
<li><span class="parameter">nameHint</span>
<span class="types"><a class="type" href="https://www.lua.org/manual/5.1/manual.html#5.4">string</a></span>
</li>
<li><span class="parameter">dataType</span>
<span class="types"><a class="type" href="https://www.lua.org/manual/5.1/manual.html#5.4">string</a></span>
</li>
<li><span class="parameter">location</span>
<span class="types"><a class="type" href="https://www.lua.org/manual/5.1/manual.html#5.4">string</a></span>
</li>
<li><span class="parameter">data</span>
<span class="types"><span class="type">any</span></span>
</li>
</ul>
</dd>
</dl>
</div> <!-- id="content" -->
</div> <!-- id="main" -->
<div id="about">
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.6</a></i>
<i style="float:right;">Last updated 2022-12-18 16:40:03 </i>
</div> <!-- id="about" -->
</div> <!-- id="container" -->
</body>
</html>

View file

@ -30,64 +30,39 @@
<li><a href="../index.html">Index</a></li>
</ul>
<h2>Contents</h2>
<ul>
<li><a href="#Functions">Functions</a></li>
</ul>
<h2>Modules</h2>
<ul class="nowrap">
<li><strong>LuaScene</strong></li>
<li><a href="../modules/vector3.html">vector3</a></li>
<li><strong>sk_input</strong></li>
<li><a href="../modules/LuaMesh.html">LuaMesh</a></li>
<li><a href="../modules/sk_transform.html">sk_transform</a></li>
<li><a href="../modules/sk_definition_writer.html">sk_definition_writer</a></li>
<li><a href="../modules/sk_math.html">sk_math</a></li>
<li><a href="../modules/sk_scene.html">sk_scene</a></li>
</ul>
</div>
<div id="content">
<h1>Module <code>LuaScene</code></h1>
<p>Scene functions</p>
<h1>Module <code>sk_input</code></h1>
<p></p>
<p></p>
<h2><a href="#Functions">Functions</a></h2>
<table class="function_list">
<tr>
<td class="name" nowrap><a href="#export_default_mesh">export_default_mesh ()</a></td>
<td class="summary">Generates mesh and animation data from the current scene</td>
</tr>
</table>
<br/>
<br/>
<h2 class="section-header "><a name="Functions"></a>Functions</h2>
<dl class="function">
<dt>
<a name = "export_default_mesh"></a>
<strong>export_default_mesh ()</strong>
</dt>
<dd>
Generates mesh and animation data from the current scene
</dd>
</dl>
</div> <!-- id="content" -->
</div> <!-- id="main" -->
<div id="about">
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.6</a></i>
<i style="float:right;">Last updated 2022-10-01 11:25:20 </i>
<i style="float:right;">Last updated 2022-12-18 16:40:03 </i>
</div> <!-- id="about" -->
</div> <!-- id="container" -->
</body>

View file

@ -0,0 +1,304 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<head>
<title>Reference</title>
<link rel="stylesheet" href="../ldoc.css" type="text/css" />
</head>
<body>
<div id="container">
<div id="product">
<div id="product_logo"></div>
<div id="product_name"><big><b></b></big></div>
<div id="product_description"></div>
</div> <!-- id="product" -->
<div id="main">
<!-- Menu -->
<div id="navigation">
<br/>
<h1>skeletool64</h1>
<ul>
<li><a href="../index.html">Index</a></li>
</ul>
<h2>Contents</h2>
<ul>
<li><a href="#Functions">Functions</a></li>
<li><a href="#Tables">Tables</a></li>
</ul>
<h2>Modules</h2>
<ul class="nowrap">
<li><a href="../modules/sk_input.html">sk_input</a></li>
<li><a href="../modules/LuaMesh.html">LuaMesh</a></li>
<li><a href="../modules/sk_transform.html">sk_transform</a></li>
<li><a href="../modules/sk_definition_writer.html">sk_definition_writer</a></li>
<li><strong>sk_math</strong></li>
<li><a href="../modules/sk_scene.html">sk_scene</a></li>
</ul>
</div>
<div id="content">
<h1>Module <code>sk_math</code></h1>
<p></p>
<p></p>
<h2><a href="#Functions">Functions</a></h2>
<table class="function_list">
<tr>
<td class="name" nowrap><a href="#vector3">vector3 (x, y, z)</a></td>
<td class="summary">creates a new 3d vector</td>
</tr>
<tr>
<td class="name" nowrap><a href="#box3">box3 (min, max)</a></td>
<td class="summary">creates a box3</td>
</tr>
<tr>
<td class="name" nowrap><a href="#quaternion">quaternion (x, y, z, w)</a></td>
<td class="summary">creates a new quaternion</td>
</tr>
</table>
<h2><a href="#Tables">Tables</a></h2>
<table class="function_list">
<tr>
<td class="name" nowrap><a href="#Vector3">Vector3</a></td>
<td class="summary"></td>
</tr>
<tr>
<td class="name" nowrap><a href="#Box3">Box3</a></td>
<td class="summary"></td>
</tr>
<tr>
<td class="name" nowrap><a href="#Quaternion">Quaternion</a></td>
<td class="summary"></td>
</tr>
</table>
<br/>
<br/>
<h2 class="section-header "><a name="Functions"></a>Functions</h2>
<dl class="function">
<dt>
<a name = "vector3"></a>
<strong>vector3 (x, y, z)</strong>
</dt>
<dd>
creates a new 3d vector
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">x</span>
<span class="types"><span class="type">number</span></span>
the x value for the vector
</li>
<li><span class="parameter">y</span>
<span class="types"><span class="type">number</span></span>
the x value for the vector
</li>
<li><span class="parameter">z</span>
<span class="types"><span class="type">number</span></span>
the x value for the vector
</li>
</ul>
<h3>Returns:</h3>
<ol>
<span class="types"><a class="type" href="../modules/sk_math.html#Vector3">Vector3</a></span>
</ol>
</dd>
<dt>
<a name = "box3"></a>
<strong>box3 (min, max)</strong>
</dt>
<dd>
creates a box3
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">min</span>
<span class="types"><a class="type" href="../modules/sk_math.html#Vector3">Vector3</a></span>
</li>
<li><span class="parameter">max</span>
<span class="types"><a class="type" href="../modules/sk_math.html#Vector3">Vector3</a></span>
</li>
</ul>
<h3>Returns:</h3>
<ol>
<span class="types"><a class="type" href="../modules/sk_math.html#Box3">Box3</a></span>
</ol>
</dd>
<dt>
<a name = "quaternion"></a>
<strong>quaternion (x, y, z, w)</strong>
</dt>
<dd>
creates a new quaternion
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">x</span>
<span class="types"><span class="type">number</span></span>
the x value for the quaternion
</li>
<li><span class="parameter">y</span>
<span class="types"><span class="type">number</span></span>
the x value for the quaternion
</li>
<li><span class="parameter">z</span>
<span class="types"><span class="type">number</span></span>
the x value for the quaternion
</li>
<li><span class="parameter">w</span>
<span class="types"><span class="type">number</span></span>
the x value for the quaternion
</li>
</ul>
<h3>Returns:</h3>
<ol>
<span class="types"><a class="type" href="../modules/sk_math.html#Quaternion">Quaternion</a></span>
</ol>
</dd>
</dl>
<h2 class="section-header "><a name="Tables"></a>Tables</h2>
<dl class="function">
<dt>
<a name = "Vector3"></a>
<strong>Vector3</strong>
</dt>
<dd>
<h3>Fields:</h3>
<ul>
<li><span class="parameter">x</span>
<span class="types"><span class="type">number</span></span>
</li>
<li><span class="parameter">y</span>
<span class="types"><span class="type">number</span></span>
</li>
<li><span class="parameter">z</span>
<span class="types"><span class="type">number</span></span>
</li>
</ul>
</dd>
<dt>
<a name = "Box3"></a>
<strong>Box3</strong>
</dt>
<dd>
<h3>Fields:</h3>
<ul>
<li><span class="parameter">min</span>
<span class="types"><a class="type" href="../modules/sk_math.html#Vector3">Vector3</a></span>
</li>
<li><span class="parameter">max</span>
<span class="types"><a class="type" href="../modules/sk_math.html#Vector3">Vector3</a></span>
</li>
</ul>
</dd>
<dt>
<a name = "Quaternion"></a>
<strong>Quaternion</strong>
</dt>
<dd>
<h3>Fields:</h3>
<ul>
<li><span class="parameter">x</span>
<span class="types"><span class="type">number</span></span>
</li>
<li><span class="parameter">y</span>
<span class="types"><span class="type">number</span></span>
</li>
<li><span class="parameter">z</span>
<span class="types"><span class="type">number</span></span>
</li>
<li><span class="parameter">w</span>
<span class="types"><span class="type">number</span></span>
</li>
</ul>
</dd>
</dl>
</div> <!-- id="content" -->
</div> <!-- id="main" -->
<div id="about">
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.6</a></i>
<i style="float:right;">Last updated 2022-12-18 16:40:03 </i>
</div> <!-- id="about" -->
</div> <!-- id="container" -->
</body>
</html>

View file

@ -0,0 +1,251 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<head>
<title>Reference</title>
<link rel="stylesheet" href="../ldoc.css" type="text/css" />
</head>
<body>
<div id="container">
<div id="product">
<div id="product_logo"></div>
<div id="product_name"><big><b></b></big></div>
<div id="product_description"></div>
</div> <!-- id="product" -->
<div id="main">
<!-- Menu -->
<div id="navigation">
<br/>
<h1>skeletool64</h1>
<ul>
<li><a href="../index.html">Index</a></li>
</ul>
<h2>Contents</h2>
<ul>
<li><a href="#Functions">Functions</a></li>
<li><a href="#Tables">Tables</a></li>
</ul>
<h2>Modules</h2>
<ul class="nowrap">
<li><a href="../modules/sk_input.html">sk_input</a></li>
<li><a href="../modules/LuaMesh.html">LuaMesh</a></li>
<li><a href="../modules/sk_transform.html">sk_transform</a></li>
<li><a href="../modules/sk_definition_writer.html">sk_definition_writer</a></li>
<li><a href="../modules/sk_math.html">sk_math</a></li>
<li><strong>sk_scene</strong></li>
</ul>
</div>
<div id="content">
<h1>Module <code>sk_scene</code></h1>
<p></p>
<p></p>
<h2><a href="#Functions">Functions</a></h2>
<table class="function_list">
<tr>
<td class="name" nowrap><a href="#export_default_mesh">export_default_mesh ()</a></td>
<td class="summary">Generates mesh and animation data from the current scene</td>
</tr>
<tr>
<td class="name" nowrap><a href="#nodes_for_type">nodes_for_type (prefix)</a></td>
<td class="summary">Returns a list of nodes with the given string prefix</td>
</tr>
<tr>
<td class="name" nowrap><a href="#node_with_name">node_with_name (name)</a></td>
<td class="summary">Returns a node with the given name</td>
</tr>
</table>
<h2><a href="#Tables">Tables</a></h2>
<table class="function_list">
<tr>
<td class="name" nowrap><a href="#Node">Node</a></td>
<td class="summary">A scene node</td>
</tr>
<tr>
<td class="name" nowrap><a href="#NodeWithArguments">NodeWithArguments</a></td>
<td class="summary">A pairing of nodes and pre parsed node arguments</td>
</tr>
</table>
<br/>
<br/>
<h2 class="section-header "><a name="Functions"></a>Functions</h2>
<dl class="function">
<dt>
<a name = "export_default_mesh"></a>
<strong>export_default_mesh ()</strong>
</dt>
<dd>
Generates mesh and animation data from the current scene
<h3>Returns:</h3>
<ol>
<li>
<span class="types"><span class="type">sk_definition_writer.RawType</span></span>
model</li>
<li>
<span class="types"><span class="type">sk_definition_writer.RawType</span></span>
material</li>
</ol>
</dd>
<dt>
<a name = "nodes_for_type"></a>
<strong>nodes_for_type (prefix)</strong>
</dt>
<dd>
Returns a list of nodes with the given string prefix
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">prefix</span>
<span class="types"><a class="type" href="https://www.lua.org/manual/5.1/manual.html#5.4">string</a></span>
the string prefix to search
</li>
</ul>
<h3>Returns:</h3>
<ol>
<span class="types"><a class="type" href="../modules/sk_scene.html#NodeWithArguments">NodeWithArguments</a></span>
</ol>
</dd>
<dt>
<a name = "node_with_name"></a>
<strong>node_with_name (name)</strong>
</dt>
<dd>
Returns a node with the given name
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">name</span>
<span class="types"><a class="type" href="https://www.lua.org/manual/5.1/manual.html#5.4">string</a></span>
</li>
</ul>
<h3>Returns:</h3>
<ol>
<span class="types"><a class="type" href="../modules/sk_scene.html#Node">Node</a></span>
result
</ol>
</dd>
</dl>
<h2 class="section-header "><a name="Tables"></a>Tables</h2>
<dl class="function">
<dt>
<a name = "Node"></a>
<strong>Node</strong>
</dt>
<dd>
A scene node
<h3>Fields:</h3>
<ul>
<li><span class="parameter">name</span>
<span class="types"><a class="type" href="https://www.lua.org/manual/5.1/manual.html#5.4">string</a></span>
</li>
<li><span class="parameter">transformation</span>
<span class="types"><span class="type">sk_transform.Transform</span></span>
</li>
<li><span class="parameter">full_transformation</span>
<span class="types"><span class="type">sk_transform.Transform</span></span>
</li>
<li><span class="parameter">parent</span>
<span class="types"><a class="type" href="../modules/sk_scene.html#Node">Node</a></span>
</li>
<li><span class="parameter">children</span>
<span class="types"><a class="type" href="../modules/sk_scene.html#Node">{Node,...}</a></span>
</li>
<li><span class="parameter">meshes</span>
<span class="types"><span class="type">{LuaMesh.Mesh,...}</span></span>
</li>
</ul>
</dd>
<dt>
<a name = "NodeWithArguments"></a>
<strong>NodeWithArguments</strong>
</dt>
<dd>
A pairing of nodes and pre parsed node arguments
<h3>Fields:</h3>
<ul>
<li><span class="parameter">node</span>
<span class="types"><a class="type" href="../modules/sk_scene.html#Node">Node</a></span>
</li>
<li><span class="parameter">arguments</span>
<span class="types"><a class="type" href="https://www.lua.org/manual/5.1/manual.html#5.4">{string,...}</a></span>
the list is strings produced by splitting the node name by spaces
</li>
</ul>
</dd>
</dl>
</div> <!-- id="content" -->
</div> <!-- id="main" -->
<div id="about">
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.6</a></i>
<i style="float:right;">Last updated 2022-12-18 16:40:03 </i>
</div> <!-- id="about" -->
</div> <!-- id="container" -->
</body>
</html>

View file

@ -0,0 +1,113 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<head>
<title>Reference</title>
<link rel="stylesheet" href="../ldoc.css" type="text/css" />
</head>
<body>
<div id="container">
<div id="product">
<div id="product_logo"></div>
<div id="product_name"><big><b></b></big></div>
<div id="product_description"></div>
</div> <!-- id="product" -->
<div id="main">
<!-- Menu -->
<div id="navigation">
<br/>
<h1>skeletool64</h1>
<ul>
<li><a href="../index.html">Index</a></li>
</ul>
<h2>Contents</h2>
<ul>
<li><a href="#Class_Transform">Class Transform </a></li>
</ul>
<h2>Modules</h2>
<ul class="nowrap">
<li><a href="../modules/sk_input.html">sk_input</a></li>
<li><a href="../modules/LuaMesh.html">LuaMesh</a></li>
<li><strong>sk_transform</strong></li>
<li><a href="../modules/sk_definition_writer.html">sk_definition_writer</a></li>
<li><a href="../modules/sk_math.html">sk_math</a></li>
<li><a href="../modules/sk_scene.html">sk_scene</a></li>
</ul>
</div>
<div id="content">
<h1>Module <code>sk_transform</code></h1>
<p></p>
<p></p>
<h2><a href="#Class_Transform">Class Transform </a></h2>
<table class="function_list">
<tr>
<td class="name" nowrap><a href="#Transform:decompose">Transform:decompose ()</a></td>
<td class="summary"></td>
</tr>
</table>
<br/>
<br/>
<h2 class="section-header has-description"><a name="Class_Transform"></a>Class Transform </h2>
<div class="section-description">
A 4x4 matrix transform
</div>
<dl class="function">
<dt>
<a name = "Transform:decompose"></a>
<strong>Transform:decompose ()</strong>
</dt>
<dd>
<h3>Returns:</h3>
<ol>
<li>
<span class="types"><span class="type">vector3.Vector3</span></span>
scale</li>
<li>
<span class="types"><span class="type">quaternion.Quaternion</span></span>
rotation</li>
<li>
<span class="types"><span class="type">vector3.Vector3</span></span>
position</li>
</ol>
</dd>
</dl>
</div> <!-- id="content" -->
</div> <!-- id="main" -->
<div id="about">
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.6</a></i>
<i style="float:right;">Last updated 2022-12-18 16:40:03 </i>
</div> <!-- id="about" -->
</div> <!-- id="container" -->
</body>
</html>

View file

@ -1,6 +0,0 @@
Box3 = {}
function box3(min, max)
return setmetatable({ min = min, max = max }, Box3)
end

View file

@ -1,34 +0,0 @@
Quaternion = {}
function quaternion(x, y, z, w)
return setmetatable({ x = x, y = y, z = z, w = w }, Quaternion)
end
function quaternionConjugate(input)
return quaternion(-input.x, -input.y, -input.z, input.w)
end
function Quaternion.__tostring(v)
return 'quaternion(' .. v.x .. ', ' .. v.y .. ', ' .. v.z .. ', ' .. v.w .. ')'
end
function Quaternion.__mul(a, b)
if (isVector3(b)) then
local result = a * quaternion(b.x, b.y, b.z, 0) * quaternionConjugate(a)
return vector3(result.x, result.y, result.z)
elseif (isQuaternion(b)) then
return quaternion(
a.w*b.x + a.x*b.w + a.y*b.z - a.z*b.y,
a.w*b.y + a.y*b.w + a.z*b.x - a.x*b.z,
a.w*b.z + a.z*b.w + a.x*b.y - a.y*b.x,
a.w*b.w - a.x*b.x - a.y*b.y - a.z*b.z
)
else
error("Expected vector3 or quaternion got " .. tostring(b))
end
end
function isQuaternion(obj)
return type(obj) == 'table' and type(obj.x) == 'number' and type(obj.y) == 'number' and type(obj.z) == 'number' and type(obj.w) == 'number'
end

View file

@ -1,19 +0,0 @@
local node_name_cache = nil
local function build_node_with_name_cache(node)
node_name_cache[node.name] = node
for _, child in pairs(node.children) do
build_node_with_name_cache(child)
end
end
function node_with_name(name)
if (not node_name_cache) then
node_name_cache = {}
build_node_with_name_cache(scene.root)
end
return node_name_cache[name]
end

View file

@ -1,32 +1,74 @@
--- @module sk_definition_writer
local exports = {}
local pending_definitions = {}
--- @table RefType
local RefType = {}
function reference_to(value, index)
--- creates a pointer to another piece of data
--- the data being referenced must be added to the output
--- via add_definition
---@function reference_to
---@tparam any value the value to reference
---@tparam[opt] integer index if value is an array, you can specify the element to reference using this index
---@treturn RefType result
local function reference_to(value, index)
return setmetatable({ value = value, index = index }, RefType)
end
function is_reference_type(value)
exports.reference_to = reference_to
--- returns true if value is a reference
---@function is_reference_type
---@tparam any value any
---@treturn boolean result
local function is_reference_type(value)
return getmetatable(value) == RefType
end
exports.is_reference_type = is_reference_type
--- @table RawType
local RawType = {}
function raw(value)
local function raw(value)
return setmetatable({ value = value}, RawType)
end
function is_raw(value)
--- renders a string directly in the ouptut instead of wrapping the output in quotes
---@function raw
---@tparam string value
---@treturn RawType result
exports.raw = raw
--- returns true if value is a RawType
---@function is_raw
---@tparam any value
---@treturn boolean result
local function is_raw(value)
return getmetatable(value) == RawType
end
exports.is_raw = is_raw
null_value = raw("NULL")
--- alias for raw("NULL")
--- @table null_value
local null_value = raw("NULL")
exports.null_value = null_value
--- @table MacroType
local MacroType = {}
function macro(name, ...)
--- Generates as a macro eg `macro("MACRO_NAME", 1, 2)` will be displayed as
--- MACRO_NAME(1, 2) in the c file output
---@function macro
---@tparam string name
---@tparam {any,...} ...
---@treturn MacroType result
local function macro(name, ...)
if (type(name) ~= "string") then
error("name should be of type string got " .. type(name))
end
@ -34,10 +76,18 @@ function macro(name, ...)
return setmetatable({ name = name, args = {...}}, MacroType)
end
function is_macro(value)
exports.macro = macro
--- Returns true if value is of type MacroType
---@function is_macro
---@tparam any value
---@treturn boolean
local function is_macro(value)
return getmetatable(value) == MacroType
end
exports.is_macro = is_macro
local function validate_definition(data, visited, name_path)
if (visited[data]) then
error("Circular reference found '" .. name_path .. "'")
@ -87,7 +137,13 @@ local function validate_definition(data, visited, name_path)
return true
end
function add_definition(nameHint, dataType, location, data)
--- Outputs a c file defintion
---@function add_definition
---@tparam string nameHint
---@tparam string dataType the c type the definition is, if it is an array it should end in []
---@tparam string location the file suffix where this definiton should be located in
---@tparam any data The data of the file definition
local function add_definition(nameHint, dataType, location, data)
if (type(nameHint) ~= "string") then
error("nameHint should be a string")
end
@ -114,6 +170,8 @@ function add_definition(nameHint, dataType, location, data)
return true
end
exports.add_definition = add_definition
local function populate_name_mapping(path, object, result)
if (type(object) ~= "table") then
return
@ -200,13 +258,29 @@ local function replace_references(object, name_mapping, name_path)
return result
end
function consume_pending_definitions()
---@table PendingDefinition
---@tfield string nameHint
---@tfield string dataType
---@tfield string location
---@tfield any data
--- Returns and clears all definitions that have been created using add_definiton
--- meant for use in the c code
---@function consume_pending_definitions
---@treturn {PendingDefinition,...} result
local function consume_pending_definitions()
local result = pending_definitions
consume_pending_definitions = {}
return result
end
function process_definitions(definitions)
exports.consume_pending_definitions = consume_pending_definitions
--- Processes definitions correctly connecting references
--- meant for use in the c code
---@function process_definitions
---@tparam {PendingDefinition,...} definitions
local function process_definitions(definitions)
local name_mapping = {}
for k, v in pairs(definitions) do
@ -219,3 +293,7 @@ function process_definitions(definitions)
v.data = replace_references(v.data, name_mapping, v.name)
end
end
exports.process_definitions = process_definitions
return exports

123
skelatool64/lua/sk_math.lua Normal file
View file

@ -0,0 +1,123 @@
--- @module sk_math
local exports = {}
--- @table Vector3
--- @tfield number x
--- @tfield number y
--- @tfield number z
local Vector3 = {}
exports.Vector3 = exports
--- creates a new 3d vector
--- @function vector3
--- @tparam number x the x value for the vector
--- @tparam number y the x value for the vector
--- @tparam number z the x value for the vector
--- @treturn Vector3
local function vector3(x, y, z)
return setmetatable({ x = x, y = y, z = z }, Vector3)
end
exports.vector3 = vector3
function Vector3.__add(a, b)
if (type(a) == 'number') then
return vector3(a + b.x, a + b.y, a + b.z)
end
if (type(b) == 'number') then
return vector3(a.x + b, a.y + b, a.z + b)
end
if (type(b) ~= 'table' or type(b.x) ~= 'number' or type(b.y) ~= 'number' or type(b.z) ~= 'number') then
error('Vector3.__add expected another vector as second operand')
end
return vector3(a.x + b.x, a.y + b.y, a.z + b.z)
end
function Vector3.__tostring(v)
return 'vector3(' .. v.x .. ', ' .. v.y .. ', ' .. v.z .. ')'
end
local function isVector3(obj)
return type(obj) == 'table' and type(obj.x) == 'number' and type(obj.y) == 'number' and type(obj.z) == 'number' and obj.w == nil
end
exports.isVector3 = isVector3
--- @table Box3
--- @tfield Vector3 min
--- @tfield Vector3 max
local Box3 = {}
exports.Box3 = Box3
--- creates a box3
--- @function box3
--- @tparam Vector3 min
--- @tparam Vector3 max
--- @treturn Box3
local function box3(min, max)
return setmetatable({ min = min, max = max }, Box3)
end
exports.box3 = box3
--- @table Quaternion
--- @tfield number x
--- @tfield number y
--- @tfield number z
--- @tfield number w
local Quaternion = {}
exports.Quaternion = Quaternion
--- creates a new quaternion
--- @function quaternion
--- @tparam number x the x value for the quaternion
--- @tparam number y the x value for the quaternion
--- @tparam number z the x value for the quaternion
--- @tparam number w the x value for the quaternion
--- @treturn Quaternion
local function quaternion(x, y, z, w)
return setmetatable({ x = x, y = y, z = z, w = w }, Quaternion)
end
exports.quaternion = quaternion
local function quaternionConjugate(input)
return quaternion(-input.x, -input.y, -input.z, input.w)
end
exports.quaternionConjugate = quaternionConjugate
function Quaternion.__tostring(v)
return 'quaternion(' .. v.x .. ', ' .. v.y .. ', ' .. v.z .. ', ' .. v.w .. ')'
end
function Quaternion.__mul(a, b)
if (isVector3(b)) then
local result = a * quaternion(b.x, b.y, b.z, 0) * quaternionConjugate(a)
return vector3(result.x, result.y, result.z)
elseif (isQuaternion(b)) then
return quaternion(
a.w*b.x + a.x*b.w + a.y*b.z - a.z*b.y,
a.w*b.y + a.y*b.w + a.z*b.x - a.x*b.z,
a.w*b.z + a.z*b.w + a.x*b.y - a.y*b.x,
a.w*b.w - a.x*b.x - a.y*b.y - a.z*b.z
)
else
error("Expected vector3 or quaternion got " .. tostring(b))
end
end
local function isQuaternion(obj)
return type(obj) == 'table' and type(obj.x) == 'number' and type(obj.y) == 'number' and type(obj.z) == 'number' and type(obj.w) == 'number'
end
exports.isQuaternion = isQuaternion
return exports

View file

@ -0,0 +1,59 @@
--- @module sk_scene
local node_name_cache = nil
local exports = {}
-- Defintions from LuaScene.cpp
---A scene node
---@table Node
---@tfield string name
---@tfield sk_transform.Transform transformation
---@tfield sk_transform.Transform full_transformation
---@tfield Node parent
---@tfield {Node,...} children
---@tfield {LuaMesh.Mesh,...} meshes
--- Generates mesh and animation data from the current scene
---@function export_default_mesh
---@treturn sk_definition_writer.RawType model
---@treturn sk_definition_writer.RawType material
exports.export_default_mesh = function ()
-- implmentation overridden by LuaScene.cpp
end
-- Defintions from LuaNodeGroups.cpp
---A pairing of nodes and pre parsed node arguments
---@table NodeWithArguments
---@tfield Node node
---@tfield {string,...} arguments the list is strings produced by splitting the node name by spaces
---Returns a list of nodes with the given string prefix
---@function nodes_for_type
---@tparam string prefix the string prefix to search
---@treturn NodeWithArguments
local function build_node_with_name_cache(node)
node_name_cache[node.name] = node
for _, child in pairs(node.children) do
build_node_with_name_cache(child)
end
end
--- Returns a node with the given name
---@function node_with_name
---@tparam string name
---@treturn Node result
exports.node_with_name = function (name)
if (not node_name_cache) then
node_name_cache = {}
build_node_with_name_cache(scene.root)
end
return node_name_cache[name]
end
return exports

View file

@ -1,36 +0,0 @@
---
-- @module vector3
Vector3 = {}
--- creates a new 3d vector
--- @param x the x value for the vector
--- @param y the x value for the vector
--- @param z the x value for the vector
function vector3(x, y, z)
return setmetatable({ x = x, y = y, z = z }, Vector3)
end
function Vector3.__add(a, b)
if (type(a) == 'number') then
return vector3(a + b.x, a + b.y, a + b.z)
end
if (type(b) == 'number') then
return vector3(a.x + b, a.y + b, a.z + b)
end
if (type(b) ~= 'table' or type(b.x) ~= 'number' or type(b.y) ~= 'number' or type(b.z) ~= 'number') then
error('Vector3.__add expected another vector as second operand')
end
return vector3(a.x + b.x, a.y + b.y, a.z + b.z)
end
function Vector3.__tostring(v)
return 'vector3(' .. v.x .. ', ' .. v.y .. ', ' .. v.z .. ')'
end
function isVector3(obj)
return type(obj) == 'table' and type(obj.x) == 'number' and type(obj.y) == 'number' and type(obj.z) == 'number' and obj.w == nil
end

View file

@ -3,6 +3,7 @@
#include "LuaGenerator.h"
#include "../StringUtils.h"
#include "LuaMesh.h"
#include "LuaUtils.h"
std::unique_ptr<DataChunk> buildDataChunk(lua_State* L);
@ -87,7 +88,14 @@ std::unique_ptr<DataChunk> buildDataChunk(lua_State* L) {
}
if (type == LUA_TTABLE) {
lua_getglobal(L, "is_raw");
lua_getglobal(L, "require");
lua_pushstring(L, "sk_definition_writer");
lua_call(L, 1, 1);
lua_getfield(L, -1, "is_raw");
// remove sk_definition_writer module
lua_remove(L, -2);
lua_pushnil(L);
lua_copy(L, -3, -1);
lua_call(L, 1, 1);
@ -101,7 +109,14 @@ std::unique_ptr<DataChunk> buildDataChunk(lua_State* L) {
}
lua_pop(L, 1);
lua_getglobal(L, "is_macro");
lua_getglobal(L, "require");
lua_pushstring(L, "sk_definition_writer");
lua_call(L, 1, 1);
lua_getfield(L, -1, "is_macro");
// remove sk_definition_writer module
lua_remove(L, -2);
lua_pushnil(L);
lua_copy(L, -3, -1);
lua_call(L, 1, 1);
@ -172,8 +187,20 @@ int luaAddHeader(lua_State* L) {
bool dumpDefinitions(lua_State* L, CFileDefinition& fileDef, const char* filename) {
int topStart = lua_gettop(L);
lua_getglobal(L, "consume_pending_definitions");
int errcode = lua_pcall(L, 0, 1, 0);
lua_getglobal(L, "require");
lua_pushstring(L, "sk_definition_writer");
int errcode = lua_pcall(L, 1, 1, 0);
int skDefinitionWriter = lua_gettop(L);
if (checkLuaError(L, errcode, filename)) {
lua_settop(L, topStart);
return false;
}
lua_getfield(L, skDefinitionWriter, "consume_pending_definitions");
errcode = lua_pcall(L, 0, 1, 0);
if (checkLuaError(L, errcode, filename)) {
lua_settop(L, topStart);
@ -197,7 +224,7 @@ bool dumpDefinitions(lua_State* L, CFileDefinition& fileDef, const char* filenam
lua_pop(L, 1);
}
lua_getglobal(L, "process_definitions");
lua_getfield(L, skDefinitionWriter, "process_definitions");
lua_pushnil(L);
lua_copy(L, definitionArray, -1);
@ -212,7 +239,7 @@ bool dumpDefinitions(lua_State* L, CFileDefinition& fileDef, const char* filenam
lua_settop(L, definitionArray);
lua_pushnil(L); /* first key */
while (lua_next(L, topStart + 1) != 0) {
while (lua_next(L, definitionArray) != 0) {
processCFileDefinition(L, fileDef, filename);
lua_pop(L, 1);
}
@ -222,8 +249,18 @@ bool dumpDefinitions(lua_State* L, CFileDefinition& fileDef, const char* filenam
return true;
}
int luaDefinitonWriterAppend(lua_State* L) {
int moduleIndex = luaGetPrevModuleLoader(L);
CFileDefinition* fileDef = (CFileDefinition*)lua_touserdata(L, lua_upvalueindex(2));
lua_pushlightuserdata(L, fileDef);
lua_pushcclosure(L, luaAddHeader, 1);
lua_setfield(L, moduleIndex, "add_header");
return 1;
}
void populateLuaDefinitionWrite(lua_State* L, CFileDefinition& fileDef) {
lua_pushlightuserdata(L, &fileDef);
lua_pushcclosure(L, luaAddHeader, 1);
lua_setglobal(L, "add_header");
luaChainModuleLoader(L, "sk_definition_writer", luaDefinitonWriterAppend, 1);
}

View file

@ -1,9 +1,12 @@
/// @module sk_input
#include "LuaDisplayListSettings.h"
#include <string.h>
#include "./LuaMesh.h"
#include "LuaTransform.h"
#include "LuaBasicTypes.h"
#include "LuaUtils.h"
Material* luaGetMaterial(lua_State* L, const DisplayListSettings& defaults) {
int materialType = lua_type(L, -1);
@ -55,20 +58,36 @@ void fromLua(lua_State* L, DisplayListSettings& result, const DisplayListSetting
}
void populateDisplayListSettings(lua_State* L, const DisplayListSettings& defaults) {
int luaInputModuleLoader(lua_State* L) {
lua_newtable(L);
toLua(L, defaults.CreateCollisionTransform());
DisplayListSettings* defaults = (DisplayListSettings*)lua_touserdata(L, lua_upvalueindex(1));
const char* levelFilename = lua_tostring(L, lua_upvalueindex(2));
lua_newtable(L);
toLua(L, defaults->CreateCollisionTransform());
lua_setfield(L, -2, "model_transform");
toLua(L, defaults.CreateGlobalTransform());
toLua(L, defaults->CreateGlobalTransform());
lua_setfield(L, -2, "fixed_point_transform");
toLua(L, defaults.mModelScale);
toLua(L, defaults->mModelScale);
lua_setfield(L, -2, "model_scale");
toLua(L, defaults.mFixedPointScale);
toLua(L, defaults->mFixedPointScale);
lua_setfield(L, -2, "fixed_point_scale");
lua_setglobal(L, "settings");
lua_setfield(L, -3, "settings");
lua_pushstring(L, levelFilename);
lua_setfield(L, -3, "input_filename");
return 1;
}
void populateDisplayListSettings(lua_State* L, const DisplayListSettings& defaults, const std::string& levelFilename) {
lua_pushlightuserdata(L, const_cast<DisplayListSettings*>(&defaults));
lua_pushstring(L, levelFilename.c_str());
lua_pushcclosure(L, luaInputModuleLoader, 2);
luaSetModuleLoader(L, "sk_input");
}

View file

@ -6,6 +6,6 @@
void fromLua(lua_State* L, DisplayListSettings& result, const DisplayListSettings& defaults);
void populateDisplayListSettings(lua_State* L, const DisplayListSettings& defaults);
void populateDisplayListSettings(lua_State* L, const DisplayListSettings& defaults, const std::string& levelFilename);
#endif

View file

@ -1,4 +1,3 @@
EMIT(definition_writer)
EMIT(vector3)
EMIT(quaternion)
EMIT(scene)
EMIT(sk_definition_writer)
EMIT(sk_math)
EMIT(sk_scene)

View file

@ -20,10 +20,11 @@ struct LuaFile {
const char* start;
const char* end;
const char* name;
const char* moduleName;
};
struct LuaFile luaFiles[] = {
#define EMIT(name) {_binary_build_lua_##name##_out_start, _binary_build_lua_##name##_out_end, "lua/" #name ".lua"},
#define EMIT(name) {_binary_build_lua_##name##_out_start, _binary_build_lua_##name##_out_end, "lua/" #name ".lua", #name},
#include "LuaFiles.h"
#undef EMIT
};
@ -44,6 +45,32 @@ bool checkLuaError(lua_State *L, int errCode, const char* filename) {
return false;
}
int loadPrecompiledModule(lua_State* L) {
const char* moduleName = lua_tostring(L, lua_upvalueindex(1));
for (unsigned i = 0; i < sizeof(luaFiles) / sizeof(*luaFiles); ++i) {
struct LuaFile* file = &luaFiles[i];
if (strcmp(moduleName, file->moduleName) != 0) {
continue;
}
luaL_loadbuffer(L, file->start, file->end - file->start, file->name);
int errCode = lua_pcall(L, 0, 1, 0);
if (checkLuaError(L, errCode, file->name)) {
lua_close(L);
exit(1);
return 0;
}
return 1;
}
return 0;
}
void generateFromLuaScript(
const std::string& levelFilename,
const std::string& filename,
@ -55,27 +82,25 @@ void generateFromLuaScript(
lua_State *L = luaL_newstate();
luaL_openlibs(L);
generateLuaTransform(L);
populateLuaNodeGroups(L, nodeGroups);
populateLuaMesh(L, scene, fileDefinition, settings);
populateLuaDefinitionWrite(L, fileDefinition);
populateDisplayListSettings(L, settings);
lua_getglobal(L, "package");
lua_getfield(L, -1, "preload");
for (unsigned i = 0; i < sizeof(luaFiles) / sizeof(*luaFiles); ++i) {
struct LuaFile* file = &luaFiles[i];
luaL_loadbuffer(L, file->start, file->end - file->start, file->name);
int stackSize = lua_gettop(L);
int errCode = lua_pcall(L, 0, LUA_MULTRET, 0);
if (checkLuaError(L, errCode, file->name)) {
lua_close(L);
exit(1);
return;
}
lua_settop(L, stackSize);
lua_pushstring(L, file->moduleName);
lua_pushcclosure(L, loadPrecompiledModule, 1);
lua_setfield(L, -2, file->moduleName);
}
// pop package and preload
lua_pop(L, 2);
populateDisplayListSettings(L, settings, levelFilename);
populateLuaDefinitionWrite(L, fileDefinition);
populateLuaScene(L, scene, fileDefinition, settings);
populateLuaNodeGroups(L, nodeGroups);
std::string directory = DirectoryName(filename) + "/?.lua;";
@ -87,9 +112,6 @@ void generateFromLuaScript(
lua_concat(L, 2);
lua_setfield(L, packageLocation, "path");
toLua(L, levelFilename);
lua_setglobal(L, "input_filename");
int errCode = luaL_dofile(L, filename.c_str());
if (checkLuaError(L, errCode, filename.c_str())) {
lua_close(L);

View file

@ -1,9 +1,10 @@
#include "LuaGeometry.h"
#include "LuaBasicTypes.h"
#include "LuaUtils.h"
void toLua(lua_State* L, const aiVector3D& vector) {
lua_getglobal(L, "vector3");
luaLoadModuleFunction(L, "sk_math", "vector3");
toLua(L, vector.x);
toLua(L, vector.y);
toLua(L, vector.z);
@ -11,7 +12,7 @@ void toLua(lua_State* L, const aiVector3D& vector) {
}
void toLua(lua_State* L, const aiQuaternion& quaternion) {
lua_getglobal(L, "quaternion");
luaLoadModuleFunction(L, "sk_math", "quaternion");
toLua(L, quaternion.x);
toLua(L, quaternion.y);
toLua(L, quaternion.z);
@ -20,7 +21,7 @@ void toLua(lua_State* L, const aiQuaternion& quaternion) {
}
void toLua(lua_State* L, const aiAABB& box) {
lua_getglobal(L, "box3");
luaLoadModuleFunction(L, "sk_math", "box3");
toLua(L, box.mMin);
toLua(L, box.mMax);
lua_call(L, 2, 1);

View file

@ -1,3 +1,5 @@
/// @module LuaMesh
#include "LuaMesh.h"
#include "../definition_generator/MeshDefinitionGenerator.h"
@ -9,6 +11,7 @@
#include "./LuaGeometry.h"
#include "./LuaTransform.h"
#include "./LuaUtils.h"
int luaGetVector3ArrayElement(lua_State* L) {
struct aiVector3DArray* array = (struct aiVector3DArray*)luaL_checkudata(L, 1, "aiVector3DArray");
@ -80,7 +83,7 @@ void toLua(lua_State* L, Material* material) {
lua_createtable(L, 1, 0);
lua_getglobal(L, "Material");
luaLoadModuleFunction(L, "sk_mesh", "Material");
lua_setmetatable(L, -2);
toLua(L, material->mName);
@ -132,7 +135,7 @@ int luaTransformMesh(lua_State* L) {
void meshToLua(lua_State* L, std::shared_ptr<ExtendedMesh> mesh) {
lua_createtable(L, 0, 1);
lua_getglobal(L, "Mesh");
luaLoadModuleFunction(L, "sk_mesh", "Mesh");
lua_setmetatable(L, -2);
toLua(L, mesh);
@ -141,11 +144,8 @@ void meshToLua(lua_State* L, std::shared_ptr<ExtendedMesh> mesh) {
toLua(L, mesh->mMesh->mName.C_Str());
lua_setfield(L, -2, "name");
toLua(L, mesh->bbMin);
lua_setfield(L, -2, "bbMin");
toLua(L, mesh->bbMax);
lua_setfield(L, -2, "bbMax");
toLua(L, aiAABB(mesh->bbMin, mesh->bbMax));
lua_setfield(L, -2, "bb");
lua_pushcfunction(L, luaTransformMesh);
lua_setfield(L, -2, "transform");
@ -237,6 +237,13 @@ int luaBuildRenderChunks(lua_State* L) {
return 1;
}
/***
Generates a mesh
@function generate_mesh
@tparam {RenderChunk,...} renderChunks
@tparam string file suffix where the mesh definition is written to
@tparam[opt] DisplayListOverrides changes to the display list
*/
int luaGenerateMesh(lua_State* L) {
const aiScene* scene = (const aiScene*)lua_touserdata(L, lua_upvalueindex(1));
CFileDefinition* fileDefinition = (CFileDefinition*)lua_touserdata(L, lua_upvalueindex(2));
@ -267,22 +274,38 @@ int luaGenerateMesh(lua_State* L) {
return 1;
}
void populateLuaMesh(lua_State* L, const aiScene* scene, CFileDefinition& fileDefinition, const DisplayListSettings& settings) {
lua_newtable(L);
lua_setglobal(L, "Material");
int buildMeshModule(lua_State* L) {
aiScene* scene = (aiScene*)lua_touserdata(L, lua_upvalueindex(1));
CFileDefinition* fileDefinition = (CFileDefinition*)lua_touserdata(L, lua_upvalueindex(2));
DisplayListSettings* settings = (DisplayListSettings*)lua_touserdata(L, lua_upvalueindex(3));
lua_newtable(L);
lua_setglobal(L, "Mesh");
lua_pushlightuserdata(L, const_cast<aiScene*>(scene));
lua_pushlightuserdata(L, &fileDefinition);
lua_pushlightuserdata(L, const_cast<DisplayListSettings*>(&settings));
lua_newtable(L);
lua_setfield(L, -2, "Material");
lua_newtable(L);
lua_setfield(L, -2, "Mesh");
lua_pushlightuserdata(L, scene);
lua_pushlightuserdata(L, fileDefinition);
lua_pushlightuserdata(L, settings);
lua_pushcclosure(L, luaBuildRenderChunks, 3);
lua_setglobal(L, "generate_render_chunks");
lua_setfield(L, -2, "generate_render_chunks");
lua_pushlightuserdata(L, scene);
lua_pushlightuserdata(L, fileDefinition);
lua_pushlightuserdata(L, settings);
lua_pushcclosure(L, luaGenerateMesh, 3);
lua_setfield(L, -2, "generate_mesh");
return 1;
}
void populateLuaMesh(lua_State* L, const aiScene* scene, CFileDefinition& fileDefinition, const DisplayListSettings& settings) {
lua_pushlightuserdata(L, const_cast<aiScene*>(scene));
lua_pushlightuserdata(L, &fileDefinition);
lua_pushlightuserdata(L, const_cast<DisplayListSettings*>(&settings));
lua_pushcclosure(L, luaGenerateMesh, 3);
lua_setglobal(L, "generate_mesh");
lua_pushcclosure(L, buildMeshModule, 3);
luaSetModuleLoader(L, "sk_mesh");
}

View file

@ -1,7 +1,10 @@
// lua docs defined in sk_scene.lua
#include "LuaNodeGroups.h"
#include "LuaBasicTypes.h"
#include "LuaScene.h"
#include "LuaUtils.h"
void toLua(lua_State* L, const NodeWithArguments& nodes) {
lua_createtable(L, 0, 2);
@ -24,8 +27,19 @@ int luaNodesForType(lua_State* L) {
return 1;
}
int luaNodeGroupsAppendModule(lua_State* L) {
int moduleIndex = luaGetPrevModuleLoader(L);
NodeGroups* nodeGroups = (NodeGroups*)lua_touserdata(L, lua_upvalueindex(2));
lua_pushlightuserdata(L, nodeGroups);
lua_pushcclosure(L, luaNodesForType, 1);
lua_setfield(L, moduleIndex, "nodes_for_type");
return 1;
}
void populateLuaNodeGroups(lua_State* L, NodeGroups& nodeGroups) {
lua_pushlightuserdata(L, (NodeGroups*)&nodeGroups);
lua_pushcclosure(L, luaNodesForType, 1);
lua_setglobal(L, "nodes_for_type");
luaChainModuleLoader(L, "sk_scene", luaNodeGroupsAppendModule, 1);
}

View file

@ -1,10 +1,11 @@
/// Scene functions
// docs for this file are located in sk_scene.lua
#include "LuaScene.h"
#include "LuaBasicTypes.h"
#include "LuaTransform.h"
#include "LuaMesh.h"
#include "LuaUtils.h"
#include <iostream>
#include "../definition_generator/MeshDefinitionGenerator.h"
@ -22,20 +23,27 @@ aiMatrix4x4 nodeFullTrasformation(lua_State* L, const aiNode* node) {
node = node->mParent;
}
lua_getglobal(L, "settings");
lua_getfield(L, -1, "model_transform");
aiMatrix4x4* modelTransform = (aiMatrix4x4*)lua_touserdata(L, -1);
lua_pop(L, 2);
return (*modelTransform) * result;
return (gLuaCurrentSettings->CreateCollisionTransform()) * result;
}
void luaGetMeshByIndex(lua_State* L, int indexAt0) {
meshToLua(L, gLuaCurrentFileDefinition->GetExtendedMesh(gLuaCurrentScene->mMeshes[indexAt0]));
}
int luaNodeToString(lua_State* L) {
lua_getfield(L, 1, "ptr");
aiNode* node = (aiNode*)lua_touserdata(L, -1);
std::ostringstream result;
result << "aiNode: name=" << node->mName.C_Str();
lua_pop(L, 1);
lua_pushstring(L, result.str().c_str());
return 1;
}
void toLua(lua_State* L, const aiNode* node) {
if (!node) {
lua_pushnil(L);
@ -43,7 +51,7 @@ void toLua(lua_State* L, const aiNode* node) {
}
// check if node ia already built in the cache
lua_getglobal(L, "node_cache");
lua_getglobal(L, "__sk_scene_node_cache__");
int nodeCache = lua_gettop(L);
lua_pushlightuserdata(L, const_cast<aiNode*>(node));
lua_gettable(L, nodeCache);
@ -56,7 +64,12 @@ void toLua(lua_State* L, const aiNode* node) {
lua_createtable(L, 0, 1);
int tableIndex = lua_gettop(L);
luaL_getmetatable(L, "aiNode");
if (luaL_newmetatable(L, "aiNode")) {
lua_pushcfunction(L, luaNodeToString);
lua_setfield(L, -2, "__tostring");
}
lua_setmetatable(L, tableIndex);
lua_pushlightuserdata(L, const_cast<aiNode*>(node));
@ -167,10 +180,6 @@ void toLua(lua_State* L, const aiScene* scene, CFileDefinition& fileDefinition)
lua_setfield(L, tableIndex, "meshes");
}
/***
Generates mesh and animation data from the current scene
@function export_default_mesh
*/
int luaExportDefaultMesh(lua_State* L) {
const aiScene* scene = (const aiScene*)lua_touserdata(L, lua_upvalueindex(1));
CFileDefinition* fileDefinition = (CFileDefinition*)lua_touserdata(L, lua_upvalueindex(2));
@ -179,18 +188,30 @@ int luaExportDefaultMesh(lua_State* L) {
std::cout << "Generating mesh definitions" << std::endl;
MeshDefinitionResults results = (*meshGenerator)->GenerateDefinitionsWithResults(scene, *fileDefinition);
lua_createtable(L, 0, 2);
lua_getglobal(L, "raw");
toLua(L, results.modelName);
lua_call(L, 1, 1);
lua_setfield(L, -2, "model");
lua_getglobal(L, "raw");
toLua(L, results.materialMacro);
lua_call(L, 1, 1);
lua_setfield(L, -2, "material");
return 2;
}
int luaSceneAppendModule(lua_State* L) {
int moduleIndex = luaGetPrevModuleLoader(L);
std::shared_ptr<MeshDefinitionGenerator> meshGenerator(new MeshDefinitionGenerator(*gLuaCurrentSettings));
meshGenerator->TraverseScene(gLuaCurrentScene);
meshGenerator->PopulateBones(gLuaCurrentScene, *gLuaCurrentFileDefinition);
lua_newtable(L);
lua_setglobal(L, "__sk_scene_node_cache__");
toLua(L, gLuaCurrentScene, *gLuaCurrentFileDefinition);
lua_setfield(L, moduleIndex, "scene");
lua_pushlightuserdata(L, const_cast<aiScene*>(gLuaCurrentScene));
lua_pushlightuserdata(L, gLuaCurrentFileDefinition);
toLua(L, meshGenerator);
lua_pushcclosure(L, luaExportDefaultMesh, 3);
lua_setfield(L, moduleIndex, "export_default_mesh");
return 1;
}
@ -200,20 +221,5 @@ void populateLuaScene(lua_State* L, const aiScene* scene, CFileDefinition& fileD
gLuaCurrentFileDefinition = &fileDefinition;
gLuaCurrentSettings = &settings;
std::shared_ptr<MeshDefinitionGenerator> meshGenerator(new MeshDefinitionGenerator(settings));
meshGenerator->TraverseScene(scene);
meshGenerator->PopulateBones(scene, fileDefinition);
lua_newtable(L);
lua_setglobal(L, "node_cache");
toLua(L, scene, fileDefinition);
lua_setglobal(L, "scene");
lua_pushlightuserdata(L, const_cast<aiScene*>(scene));
lua_pushlightuserdata(L, &fileDefinition);
toLua(L, meshGenerator);
lua_pushcclosure(L, luaExportDefaultMesh, 3);
lua_setglobal(L, "export_default_mesh");
luaChainModuleLoader(L, "sk_scene", luaSceneAppendModule, 0);
}

View file

@ -1,7 +1,14 @@
/// @module sk_transform
#include "LuaTransform.h"
#include "LuaBasicTypes.h"
/***
A 4x4 matrix transform
@type Transform
*/
void toLua(lua_State* L, const aiMatrix4x4& matrix) {
aiMatrix4x4* result = (aiMatrix4x4*)lua_newuserdata(L, sizeof(aiMatrix4x4));
new(result) aiMatrix4x4(matrix);
@ -19,6 +26,12 @@ void fromLua(lua_State* L, aiMatrix4x4& matrix) {
lua_pop(L, 1);
}
/***
@function decompose
@treturn vector3.Vector3 scale
@treturn quaternion.Quaternion rotation
@treturn vector3.Vector3 position
*/
int luaTransformDecomponse(lua_State* L) {
aiMatrix4x4* mtx = (aiMatrix4x4*)luaL_checkudata(L, 1, "aiMatrix4x4");

View file

@ -0,0 +1,49 @@
#include "LuaUtils.h"
void luaLoadModuleFunction(lua_State* L, const char* moduleName, const char* functionName) {
lua_getglobal(L, "require");
lua_pushstring(L, moduleName);
lua_call(L, 1, 1);
lua_getfield(L, -1, functionName);
lua_remove(L, -2);
}
void luaSetModuleLoader(lua_State* L, const char* moduleName) {
lua_getglobal(L, "package");
lua_getfield(L, -1, "preload");
lua_rotate(L, -3, -1);
lua_setfield(L, -2, moduleName);
lua_pop(L, 2);
}
void luaChainModuleLoader(lua_State* L, const char* moduleName, lua_CFunction function, int additionalClosure) {
int startingTop = lua_gettop(L);
lua_getglobal(L, "package");
lua_getfield(L, -1, "preload");
lua_getfield(L, -1, "sk_scene");
if (additionalClosure) {
lua_rotate(L, startingTop - additionalClosure + 1, -additionalClosure);
}
lua_pushcclosure(L, function, 1 + additionalClosure);
lua_setfield(L, -2, "sk_scene");
// pop package and preload
lua_pop(L, 2);
}
int luaGetPrevModuleLoader(lua_State* L) {
int nArgs = lua_gettop(L);
lua_pushnil(L);
lua_copy(L, lua_upvalueindex(1), -1);
lua_insert(L, 1);
lua_call(L, nArgs, 1);
return lua_gettop(L);
}

View file

@ -0,0 +1,14 @@
#ifndef __LUA_UTILS_H__
#define __LUA_UTILS_H__
#include <lua.hpp>
void luaLoadModuleFunction(lua_State* L, const char* moduleName, const char* functionName);
void luaSetModuleLoader(lua_State* L, const char* moduleName);
void luaChainModuleLoader(lua_State* L, const char* moduleName, lua_CFunction function, int additionalClosure);
int luaGetPrevModuleLoader(lua_State* L);
#endif