Do not bundle default system_config (prefer built-in defaults)
[ardour.git] / tools / fmt-luadoc.php
index 2656b7e330b5a95d5d90e6b81f2c163a9f5f92e3..b13e38617caf77f2b7c31a75ca67ba958f20d006 100755 (executable)
@@ -34,9 +34,18 @@ foreach (json_decode ($json, true) as $b) {
                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']));
+       $b ['ldec'] = preg_replace ('/_VampHost::/', '', $b['ldec']);
+       $b ['decl'] = preg_replace ('/_VampHost::/', '', $b['decl']);
        if (isset ($b['ret'])) {
                $b['ret'] = preg_replace ('/ const/', '', preg_replace ('/ const&/', '', $b['ret']));
+               $b['ret'] = preg_replace ('/_VampHost::/', '', $b['ret']);
+       }
+       if (isset ($b['parent'])) {
+               $b ['parent'] = preg_replace ('/_VampHost::/', '', $b['parent']);
        }
        $doc[] = $b;
 }
@@ -88,11 +97,15 @@ function arg2lua ($argtype, $flags = 0) {
        $arg = preg_replace ('/ $/', '', $arg);
 
        # filter out basic types
-       $builtin = array ('float', 'double', 'bool', 'std::string', 'int', 'long', 'unsigned long', 'unsigned int', 'unsigned char', 'char', 'void', 'char*', 'unsigned char*', 'void*');
+       $builtin = array ('float', 'double', 'bool', 'std::string', 'int', 'short', 'long', 'unsigned int', 'unsigned short', 'unsigned long', 'unsigned char', 'char', 'void', 'char*', 'unsigned char*', 'void*');
        if (in_array ($arg, $builtin)) {
                return array ($arg => $flags);
        }
 
+       if ($arg == 'luabridge::LuaRef') {
+               return array ('Lua-Function' => $flags | 4);
+       }
+
        # check Class declarations first
        foreach (array_merge ($classes, $consts) as $b) {
                if ($b['ldec'] == $arg) {
@@ -125,7 +138,7 @@ function stripclass ($classname, $name) {
 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) {
@@ -191,6 +204,8 @@ function canonical_decl ($b) {
                        $a = preg_replace ('/([^>]) >/', '$1>', $a);
                        $a = preg_replace ('/^Cairo::/', '', $a); // special case cairo enums
                        $a = preg_replace ('/([^ ])&/', '$1 &', $a);
+                       $a = preg_replace ('/std::vector<([^>]*)> const/', 'const std::vector<$1>', $a);
+                       $a = str_replace ('std::vector', 'vector', $a);
                        $a = str_replace ('vector', 'std::vector', $a);
                        $a = str_replace ('std::string', 'string', $a);
                        $a = str_replace ('string const', 'const string', $a);
@@ -255,7 +270,24 @@ foreach ($doc as $b) {
                $classlist[luafn2class ($b['lua'])]['ctor'][] = array (
                        'name' => luafn2class ($b['lua']),
                        'args' => decl2args ($b['ldec']),
-                       'cand' => canonical_ctor ($b)
+                       'cand' => canonical_ctor ($b),
+                       'nil' => false
+               );
+               break;
+       case "Weak/Shared Pointer NIL Constructor":
+               checkclass ($b);
+               $classlist[luafn2class ($b['lua'])]['ctor'][] = array (
+                       'name' => luafn2class ($b['lua']),
+                       'args' => decl2args ($b['ldec']),
+                       'cand' => canonical_ctor ($b),
+                       'nil' => true
+               );
+               break;
+       case "Property":
+               checkclass ($b);
+               $classlist[luafn2class ($b['lua'])]['props'][] = array (
+                       'name' => $b['lua'],
+                       'ret'  => arg2lua (datatype ($b['ldec']))
                );
                break;
        case "Data Member":
@@ -342,6 +374,17 @@ foreach ($doc as $b) {
                        '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 (
@@ -359,7 +402,6 @@ foreach ($doc as $b) {
        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 (
@@ -371,6 +413,18 @@ foreach ($doc as $b) {
                        '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
@@ -390,14 +444,17 @@ foreach ($doc as $b) {
 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'];
                        }
                }
        }
@@ -457,10 +514,19 @@ function doxydoc ($canonical_declaration) {
        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 '';
 }
 
 ################################################################################
@@ -496,6 +562,7 @@ function traverse_parent ($ns, &$inherited) {
                asort ($parents);
                foreach ($parents as $p) {
                        if (!empty ($rv)) { $rv .= ', '; }
+                       if ($p == $ns) { continue; }
                        $rv .= typelink ($p);
                        $inherited[$p] = $classlist[$p];
                        traverse_parent ($p, $inherited);
@@ -527,7 +594,10 @@ function format_args ($args) {
        foreach ($args as $a) {
                if (!$first) { $rv .= ', '; }; $first = false;
                $flags = $a[varname ($a)];
-               if ($flags & 2) {
+               if ($flags & 4) {
+                       $rv .= '<span>'.varname ($a).'</span>';
+               }
+               else if ($flags & 2) {
                        $rv .= '<em>LuaTable</em> {'.typelink (varname ($a), true, 'em').'}';
                }
                elseif ($flags & 1) {
@@ -582,7 +652,13 @@ function format_class_members ($ns, $cl, &$dups) {
                usort ($cl['ctor'], 'name_sort_cb');
                $rv.= ' <tr><th colspan="3">Constructor</th></tr>'.NL;
                foreach ($cl['ctor'] as $f) {
-                       $rv.= ' <tr><td class="def">&Copf;</td><td class="decl">';
+                       $rv.= ' <tr>';
+                       if ($f['nil']) {
+                               $rv.= '<td class="def"><abbr title="Nil Pointer Constructor">&alefsym;</abbr></td>';
+                       } else {
+                               $rv.= '<td class="def">&Copf;</td>';
+                       }
+                       $rv.= '<td class="decl">';
                        $rv.= '<span class="functionname">'.ctorname ($f['name']).'</span>';
                        $rv.= format_args ($f['args']);
                        $rv.= '</td><td class="fill"></td></tr>'.NL;
@@ -632,6 +708,34 @@ function format_class_members ($ns, $cl, &$dups) {
                        $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 properties - if any
+       if (isset ($cl['props'])) {
+               usort ($cl['props'], 'name_sort_cb');
+               $rv.= ' <tr><th colspan="3">Properties</th></tr>'.NL;
+               foreach ($cl['props'] as $f) {
+                       $rv.= ' <tr><td class="def">'.typelink (array_keys ($f['ret'])[0], false, 'em').'</td><td class="decl">';
+                       $rv.= '<span class="functionname">'.stripclass ($ns, $f['name']).'</span>';
+                       $rv.= '</td><td class="fill"></td></tr>'.NL;
+               }
+       }
+
        # print data members - if any
        if (isset ($cl['data'])) {
                usort ($cl['data'], 'name_sort_cb');
@@ -640,6 +744,8 @@ function format_class_members ($ns, $cl, &$dups) {
                        $rv.= ' <tr><td class="def">'.typelink (array_keys ($f['ret'])[0], false, 'em').'</td><td class="decl">';
                        $rv.= '<span class="functionname">'.stripclass ($ns, $f['name']).'</span>';
                        $rv.= '</td><td class="fill"></td></tr>'.NL;
+                       $f['cand'] = str_replace (':', '::', $f['name']);
+                       $rv.= format_doxydoc($f);
                }
        }
        return $rv;
@@ -700,6 +806,7 @@ div.luafooter      { text-align:center; font-size:80%; color: #888; margin: 2em
 #luaref table.classmembers td.fill { width: 99%; }
 #luaref table.classmembers span.em { font-style: italic; }
 #luaref span.functionname abbr     { text-decoration:none; cursor:default; }
+#luaref table.classmembers td.def abbr { text-decoration:none; cursor:default; }
 </style>
 </head>
 <body>
@@ -721,14 +828,9 @@ div.luafooter      { text-align:center; font-size:80%; color: #888; margin: 2em
 } else {
 
 ?>
----
-layout: default
-style: luadoc
-title: Class Reference
----
 
 <p class="warning">
-This documention is far from complete may be inaccurate and subject to change.
+This documentation is far from complete may be inaccurate and subject to change.
 </p>
 
 <?php
@@ -769,6 +871,12 @@ Operations are performed on objects. One gets a reference to an object and then
 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>
@@ -884,8 +992,8 @@ foreach ($classlist as $ns => $cl) {
        }
 
        # show original C++ declaration
-       if (isset ($cl['decl'])) {
-               echo '<p class="cdecl"><em>C&#8225;</em>: '.htmlentities ($cl['decl']).'</p>'.NL;
+       if (isset ($cl['cdecl'])) {
+               echo '<p class="cdecl"><em>C&#8225;</em>: '.htmlentities ($cl['cdecl']).'</p>'.NL;
        }
 
        # print class inheritance (direct parent *name* only)
@@ -947,6 +1055,7 @@ echo '</ul>'.NL;
 
 # 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>