X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=tools%2Ffmt-luadoc.php;h=ae333c892656556b4b469b552520a8c88273fba1;hb=302fe227b8ef96e9825a3c8f09c3851ff5e67978;hp=60d89728e363ee4f2dee8833d9b68016ef3907d4;hpb=6b33ebaafa29dc007afa1ea47749172fc8bc2164;p=ardour.git diff --git a/tools/fmt-luadoc.php b/tools/fmt-luadoc.php index 60d89728e3..ae333c8926 100755 --- a/tools/fmt-luadoc.php +++ b/tools/fmt-luadoc.php @@ -16,6 +16,13 @@ # 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 +} + ################################################################################ ################################################################################ @@ -27,16 +34,25 @@ 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; } if (count ($doc) == 0) { fwrite (STDERR, "Failed to read luadoc.json\n"); - exit (1); + exit (EXIT_FAILURE); } ################################################################################ @@ -81,11 +97,18 @@ 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); + } + if ($arg == 'LTC_TV_STANDARD') { + $arg = 'ARDOUR::DSP::LTC_TV_STANDARD'; + } + # check Class declarations first foreach (array_merge ($classes, $consts) as $b) { if ($b['ldec'] == $arg) { @@ -118,13 +141,22 @@ function stripclass ($classname, $name) { function datatype ($decl) { # TODO handle spaces in type. Works because # we don't yet have templated types (with_space ) - 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'])])) { @@ -173,8 +205,9 @@ function canonical_decl ($b) { if (!$first) { $rv .= ', '; }; $first = false; if (empty ($a)) { continue; } $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); @@ -239,7 +272,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": @@ -249,6 +299,26 @@ foreach ($doc as $b) { '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": @@ -257,9 +327,8 @@ foreach ($doc as $b) { $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)); @@ -278,6 +347,7 @@ foreach ($doc as $b) { 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': @@ -306,6 +376,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 ( @@ -323,7 +404,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 ( @@ -335,6 +415,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 @@ -354,14 +446,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']; } } } @@ -421,10 +516,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::Track::bounceable(boost::shared_ptr" + $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 ''; } ################################################################################ @@ -460,6 +564,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); @@ -491,7 +596,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 .= ''.varname ($a).''; + } + else if ($flags & 2) { $rv .= 'LuaTable {'.typelink (varname ($a), true, 'em').'}'; } elseif ($flags & 1) { @@ -546,7 +654,13 @@ function format_class_members ($ns, $cl, &$dups) { usort ($cl['ctor'], 'name_sort_cb'); $rv.= ' Constructor'.NL; foreach ($cl['ctor'] as $f) { - $rv.= ' ℂ'; + $rv.= ' '; + if ($f['nil']) { + $rv.= ''; + } else { + $rv.= 'ℂ'; + } + $rv.= ''; $rv.= ''.ctorname ($f['name']).''; $rv.= format_args ($f['args']); $rv.= ''.NL; @@ -596,6 +710,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.= ' Cast'.NL; + foreach ($cl['cast'] as $f) { + $rv.= ' '; + $rv.= typelink (varname ($f['ret']), true, 'em'); + # function declaration and arguments + $rv.= ''; + $rv.= ''.stripclass ($ns, $f['name']).''; + $rv.= format_args ($f['args']); + $rv.= ''.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.= ' Properties'.NL; + foreach ($cl['props'] as $f) { + $rv.= ' '.typelink (array_keys ($f['ret'])[0], false, 'em').''; + $rv.= ''.stripclass ($ns, $f['name']).''; + $rv.= ''.NL; + } + } + # print data members - if any if (isset ($cl['data'])) { usort ($cl['data'], 'name_sort_cb'); @@ -604,6 +746,8 @@ function format_class_members ($ns, $cl, &$dups) { $rv.= ' '.typelink (array_keys ($f['ret'])[0], false, 'em').''; $rv.= ''.stripclass ($ns, $f['name']).''; $rv.= ''.NL; + $f['cand'] = str_replace (':', '::', $f['name']); + $rv.= format_doxydoc($f); } } return $rv; @@ -613,59 +757,63 @@ function format_class_members ($ns, $cl, &$dups) { ################################################################################ # Start Output +if ($HTMLOUTPUT) { + ?> Ardour Lua Bindings
-

Ardour Lua Bindings

+

Ardour Lua Bindings

Class Documentation  |  @@ -674,7 +822,24 @@ div.footer {text-align:center; font-size:80%; color: #888; margin: 2em 0 Index

-
+ + + + + +

+This documentation is far from complete may be inaccurate and subject to change. +

+ + + +
-

Overview

+

Overview

The top-level entry point are and . Most other Classes are used indirectly starting with a Session function. e.g. Session:get_routes(). @@ -696,7 +861,7 @@ A few classes are dedicated to certain script types, e.g. Lua DSP processors hav

Detailed documentation (parameter names, method description) is not yet available. Please stay tuned.

-

Short introduction to Ardour classes

+

Short introduction to Ardour classes

Ardour's structure is object oriented. The main object is the Session. A Session contains Audio Tracks, Midi Tracks and Busses. Audio and Midi tracks are derived from a more general "Track" Object, which in turn is derived from a "Route" (aka Bus). @@ -708,12 +873,18 @@ Operations are performed on objects. One gets a reference to an object and then e.g obj = Session:route_by_name("Audio") obj:set_name("Guitar").

+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 explicitly cast to a Track. Methods for casts are provided with each class. Note that the cast may fail and return a nil reference. +

+

+Likewise multiple inheritance is a non-trivial issue in Lua. To avoid performance penalties involved with lookups, explicit casts are required in this case. One example is which is-a StatefulDestructible which inherits from both Stateful and Destructible. +

+

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 factory methods for object creation or removal.

-

Pass by Reference

+

Pass by Reference

-Since lua functions are closures, C++ methods that pass arguments by reference cannot be used as-is. +Since Lua functions are closures, C++ methods that pass arguments by reference cannot be used as-is. All parameters passed to a C++ method which uses references are returned as Lua Table. If the C++ method also returns a value it is prefixed. Two parameters are returned: the value and a Lua Table holding the parameters.

@@ -762,15 +933,15 @@ print (rv, ref[1], ref[2])
-

Pointer Classes

+

Pointer Classes

Libardour makes extensive use of reference counted boost::shared_ptr to manage lifetimes. -The Lua bindings provide a complete abstration of this. There are no pointers in lua. -For example a is a pointer in C++, but lua functions operate on it like it was a class instance. +The Lua bindings provide a complete abstraction of this. There are no pointers in Lua. +For example a is a pointer in C++, but Lua functions operate on it like it was a class instance.

-shared_ptr are reference counted. Once assigned to a lua variable, the C++ object will be kept and remains valid. -It is good practice to assign references to lua local variables or reset the variable to nil to drop the ref. +shared_ptr are reference counted. Once assigned to a Lua variable, the C++ object will be kept and remains valid. +It is good practice to assign references to Lua local variables or reset the variable to nil to drop the ref.

All pointer classes have a isnil () method. This is for two cases: @@ -780,13 +951,13 @@ may not be able to find the given plugin and hence cannot create an object.

The second case if for boost::weak_ptr. As opposed to boost::shared_ptr weak-pointers are not reference counted. The object may vanish at any time. -If lua code calls a method on a nil object, the interpreter will raise an exception and the script will not continue. +If Lua code calls a method on a nil object, the interpreter will raise an exception and the script will not continue. This is not unlike a = nil a:test() which results in en error "attempt to index a nil value".

-From the lua side of things there is no distinction between weak and shared pointers. They behave identically. -Below they're inidicated in orange and have an arrow to indicate the pointer type. -Pointer Classes cannot be created in lua scripts. It always requires a call to C++ to create the Object and obtain a reference to it. +From the Lua side of things there is no distinction between weak and shared pointers. They behave identically. +Below they're indicated in orange and have an arrow to indicate the pointer type. +Pointer Classes cannot be created in Lua scripts. It always requires a call to C++ to create the Object and obtain a reference to it.

@@ -795,7 +966,7 @@ Pointer Classes cannot be created in lua scripts. It always requires a call to C ################################# # Main output function -- Classes -echo '

Class Documentation

'.NL; +echo '

Class Documentation

'.NL; foreach ($classlist as $ns => $cl) { $dups = array (); $tbl = format_class_members ($ns, $cl, $dups); @@ -803,28 +974,28 @@ foreach ($classlist as $ns => $cl) { # format class title - depending on type if (empty ($tbl)) { # classes with no members (no ctor, no methods, no data) - echo '

 '.htmlentities ($ns).'

'.NL; + echo '

 '.htmlentities ($ns).'

'.NL; } else if (isset ($classlist[$ns]['free'])) { # free functions (no class) - echo '

 '.ctorname($ns).'

'.NL; + echo '

 '.ctorname($ns).'

'.NL; } else if (isset ($classlist[$ns]['arr'])) { # C Arrays - echo '

 '.htmlentities ($ns).'

'.NL; + echo '

 '.htmlentities ($ns).'

'.NL; } else if (isset ($classlist[$ns]['ptr'])) { # Pointer Classes - echo '

 '. htmlentities ($ns).'

'.NL; + echo '

 '. htmlentities ($ns).'

'.NL; } else { # Normal Class - echo '

 '.htmlentities ($ns).'

'.NL; + echo '

 '.htmlentities ($ns).'

'.NL; } # show original C++ declaration - if (isset ($cl['decl'])) { - echo '

C‡: '.htmlentities ($cl['decl']).'

'.NL; + if (isset ($cl['cdecl'])) { + echo '

C‡: '.htmlentities ($cl['cdecl']).'

'.NL; } # print class inheritance (direct parent *name* only) @@ -852,7 +1023,7 @@ foreach ($classlist as $ns => $cl) { foreach ($inherited as $pns => $pcl) { $tbl = format_class_members ($pns, $pcl, $dups); if (!empty ($tbl)) { - echo '

Inherited from '.$pns.'

'.NL; + echo '

Inherited from '.$pns.'

'.NL; echo ''.NL; echo $tbl; echo '
'.NL; @@ -863,9 +1034,9 @@ foreach ($classlist as $ns => $cl) { #################### # Enum and Constants -echo '

Enum/Constants

'.NL; +echo '

Enum/Constants

'.NL; foreach ($constlist as $ns => $cs) { - echo '

 '.ctorname ($ns).'

'.NL; + echo '

 '.ctorname ($ns).'

'.NL; echo '
    '.NL; foreach ($cs as $c) { echo '
  • '.ctorname ($c['lua']).'
  • '.NL; @@ -876,7 +1047,7 @@ foreach ($constlist as $ns => $cs) { ###################### # Index of all classes -echo '

    Class Index

    '.NL; +echo '

    Class Index

    '.NL; echo '
      '.NL; foreach ($classlist as $ns => $cl) { echo '
    • '.typelink($ns).'
    • '.NL; @@ -886,9 +1057,15 @@ echo '
    '.NL; # see how far there is still to go... fwrite (STDERR, "Found $dox_found annotations. missing: $dox_miss\n"); +echo ''.NL; ?>
- - - +
Ardour  - 
+'.NL; + echo ''.NL; + echo ''.NL; +}