# php tools/fmt-luadoc.php > /tmp/luadoc.html
#
+$options = getopt("m");
+if (isset ($options['m'])) {
+ $HTMLOUTPUT = false; ## set to false to output ardour-manual
+} else {
+ $HTMLOUTPUT = true; ## set to false to output ardour-manual
+}
+
################################################################################
################################################################################
if (isset ($b['version'])) { $ardourversion = $b['version']; }
continue;
}
+ # reserved lua words
+ $b ['lua'] = preg_replace ('/:_end/', ':end', $b ['lua']);
+ $b ['lua'] = preg_replace ('/:_type/', ':type', $b ['lua']);
$b ['ldec'] = preg_replace ('/ const/', '', preg_replace ('/ const&/', '', $b['decl']));
if (isset ($b['ret'])) {
$b['ret'] = preg_replace ('/ const/', '', preg_replace ('/ const&/', '', $b['ret']));
function datatype ($decl) {
# TODO handle spaces in type. Works because
# we don't yet have templated types (with_space <here >)
- return substr ($decl, 0, strpos ($decl, ' '));
+ return substr ($decl, 0, strrpos ($decl, ' '));
}
function luafn2class ($lua) {
return substr ($lua, 0, strrpos ($lua, ':'));
}
+function luafn2name ($lua) {
+ $fn = strrpos ($lua, ':');
+ if ($fn !== 0 && strlen($lua) > $fn + 1) {
+ return substr ($lua, $fn + 1);
+ }
+ my_die ('invalid class prefix: '. $name);
+}
+
+
function checkclass ($b) {
global $classlist;
if (!isset ($classlist[luafn2class ($b['lua'])])) {
'ret' => arg2lua (datatype ($b['ldec']))
);
break;
+ case "Static C Function":
+ checkclass ($b);
+ if (strpos ($b['lua'], 'ARDOUR:DataType:') === 0) {
+ # special case ARDOUR:DataType convenience c'tor
+ $args = array ();
+ $ret = array (luafn2class ($b['lua']) => 0);
+ $canon = 'ARDOUR::LuaAPI::datatype_ctor_'.strtolower (luafn2name ($b['lua'])).'(lua_State*)';
+ } else {
+ my_die ('unhandled Static C: ' . print_r($b, true));
+ }
+ $classlist[luafn2class ($b['lua'])]['func'][] = array (
+ 'bind' => $b,
+ 'name' => $b['lua'],
+ 'args' => $args,
+ 'ret' => $ret,
+ 'ref' => false,
+ 'ext' => false,
+ 'cand' => $canon
+ );
+ break;
case "C Function":
# we required C functions to be in a class namespace
case "Ext C Function":
$ret = array ('...' => 0);
$ns = luafn2class ($b['lua']);
$cls = $classlist[$ns];
- ## std::Vector std::List types
if (preg_match ('/.*<([^>]*)[ ]*>/', $cls['ldec'], $templ)) {
- // XXX -> move to C-source
+ # std::vector, std::list types
switch (stripclass($ns, $b['lua'])) {
case 'add':
#$args = array (array ('LuaTable {'.$templ[1].'}' => 0));
break;
}
} else if (strpos ($cls['type'], ' Array') !== false) {
+ # catches C:FloatArray, C:IntArray
$templ = preg_replace ('/[&*]*$/', '', $cls['ldec']);
switch (stripclass($ns, $b['lua'])) {
case 'array':
'cand' => canonical_decl ($b)
);
break;
+ case "Free C Function":
+ $funclist[luafn2class ($b['lua'])][] = array (
+ 'bind' => $b,
+ 'name' => $b['lua'],
+ 'args' => $args,
+ 'ret' => $ret,
+ 'ref' => false,
+ 'ext' => true,
+ 'cand' => str_replace (':', '::', $b['lua']).'(lua_State*)'
+ );
+ break;
case "Free Function":
case "Free Function RefReturn":
$funclist[luafn2class ($b['lua'])][] = array (
case "Weak/Shared Pointer Function":
case "Weak/Shared Pointer Function RefReturn":
case "Weak/Shared Null Check":
- case "Weak/Shared Pointer Cast":
case "Static Member Function":
checkclass ($b);
$classlist[luafn2class ($b['lua'])]['func'][] = array (
'cand' => canonical_decl ($b)
);
break;
+ case "Cast":
+ case "Weak/Shared Pointer Cast":
+ checkclass ($b);
+ $classlist[luafn2class ($b['lua'])]['cast'][] = array (
+ 'bind' => $b,
+ 'name' => $b['lua'],
+ 'args' => decl2args ($b['ldec']),
+ 'ret' => arg2lua ($b['ret']),
+ 'ref' => (strpos ($b['type'], "RefReturn") !== false),
+ 'cand' => canonical_decl ($b)
+ );
+ break;
case "Constant/Enum":
case "Constant/Enum Member":
# already handled -> $consts
foreach ($classlist as $ns => $cl) {
if (strpos ($cl['type'], ' Array') !== false) {
$classlist[$ns]['arr'] = true;
+ $classlist[$ns]['cdecl'] = $cl['decl'];
continue;
}
foreach ($classes as $c) {
if ($c['lua'] == $ns) {
if (strpos ($c['type'], 'Pointer Class') !== false) {
$classlist[$ns]['ptr'] = true;
- $classlist[$ns]['decl'] = 'boost::shared_ptr< '.$c['decl']. ' >, boost::weak_ptr< '.$c['decl']. ' >';
+ $classlist[$ns]['cdecl'] = 'boost::shared_ptr< '.$c['decl']. ' >, boost::weak_ptr< '.$c['decl']. ' >';
break;
+ } else {
+ $classlist[$ns]['cdecl'] = $c['decl'];
}
}
}
if (isset ($api[$canonical_declaration])) {
$dox_found++;
return $api[$canonical_declaration]['doc'];
- } else {
- $dox_miss++;
- return '';
}
+ // remove template namespace e.g.
+ // "ARDOUR::Track::bounceable(boost::shared_ptr<ARDOUR::Processor>"
+ // "ARDOUR::Track::bounceable(boost::shared_ptr<Processor>"
+ $cn = preg_replace ('/<[^>]*::([^>]*)>/', '<$1>', $canonical_declaration);
+ if (isset ($api[$cn])) {
+ $dox_found++;
+ return $api[$cn]['doc'];
+ }
+ #fwrite (STDERR, $canonical_declaration."\n"); # XXX DEBUG
+
+ $dox_miss++;
+ return '';
}
################################################################################
$rv.= format_doxydoc($f);
}
}
+ # print cast - if any
+ if (isset ($cl['cast'])) {
+ usort ($cl['cast'], 'name_sort_cb');
+ $rv.= ' <tr><th colspan="3">Cast</th></tr>'.NL;
+ foreach ($cl['cast'] as $f) {
+ $rv.= ' <tr><td class="def">';
+ $rv.= typelink (varname ($f['ret']), true, 'em');
+ # function declaration and arguments
+ $rv.= '</td><td class="decl">';
+ $rv.= '<span class="functionname"><abbr title="'.htmlentities($f['bind']['decl']).'">'.stripclass ($ns, $f['name']).'</abbr></span>';
+ $rv.= format_args ($f['args']);
+ $rv.= '</td><td class="fill"></td></tr>'.NL;
+ # doxygen documentation (may be empty)
+ $rv.= format_doxydoc($f);
+ }
+ }
+
# print data members - if any
if (isset ($cl['data'])) {
usort ($cl['data'], 'name_sort_cb');
################################################################################
# Start Output
+if ($HTMLOUTPUT) {
+
?><!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
</p>
</div>
-<!-- #### SNIP #### !-->
+<!-- #### SNIP #### !-->
+
+<?php
+
+} else {
+
+?>
+---
+layout: default
+style: luadoc
+title: Class Reference
+---
+
+<p class="warning">
+This documentation is far from complete may be inaccurate and subject to change.
+</p>
+
+<?php
+}
+?>
<div id="luaref">
e.g <code>obj = Session:route_by_name("Audio") obj:set_name("Guitar")</code>.
</p>
<p>
+Lua automatically follows C++ class inheritance. e.g one can directly call all SessionObject and Route methods on Track object. However lua does not automatically promote objects. A Route object which just happens to be a Track needs to be explicily cast to a Track. Methods for casts are provided with each class. Note that the cast may fail and return a <em>nil</em> reference.
+</p>
+<p>
+Likewise multiple inheritance is a <a href="http://www.lua.org/pil/16.3.html">non-trivial issue</a> in lua. To avoid performance penalties involved with lookups, explicit casts are required in this case. One example is <?=typelink('ARDOUR:SessionObject')?> which is-a StatefulDestructible which inhertis from both Stateful and Destructible.
+</p>
+<p>
Object lifetimes are managed by the Session. Most Objects cannot be directly created, but one asks the Session to create or destroy them. This is mainly due to realtime constrains:
you cannot simply remove a track that is currently processing audio. There are various <em>factory</em> methods for object creation or removal.
</p>
}
# show original C++ declaration
- if (isset ($cl['decl'])) {
- echo '<p class="cdecl"><em>C‡</em>: '.htmlentities ($cl['decl']).'</p>'.NL;
+ if (isset ($cl['cdecl'])) {
+ echo '<p class="cdecl"><em>C‡</em>: '.htmlentities ($cl['cdecl']).'</p>'.NL;
}
# print class inheritance (direct parent *name* only)
# see how far there is still to go...
fwrite (STDERR, "Found $dox_found annotations. missing: $dox_miss\n");
+echo '<!-- '.$dox_found.' / '.$dox_miss.' !-->'.NL;
?>
</div>
<div class="luafooter">Ardour <?=$ardourversion?> - <?=date('r')?></div>
+<?php
-<!-- #### SNIP #### !-->
-
-</body>
-</html>
+if ($HTMLOUTPUT) {
+ echo '<!-- #### SNIP #### !-->'.NL;
+ echo '</body>'.NL;
+ echo '</html>'.NL;
+}