comparison website/src/manual.html.luan @ 565:22bfd8a2eaee

do Table documentation; replace Table.clone and Table.sub_list with Table.copy;
author Franklin Schmidt <fschmidt@gmail.com>
date Sun, 05 Jul 2015 00:47:00 -0600
parents 7cc9d4a53d3b
children 90b93790c544
comparison
equal deleted inserted replaced
564:c8d4d69c6dd4 565:22bfd8a2eaee
89 <ul> 89 <ul>
90 <li><a href="#default_lib">Default Environment</a></li> 90 <li><a href="#default_lib">Default Environment</a></li>
91 <li><a href="#luan_lib">Basic Functions</a></li> 91 <li><a href="#luan_lib">Basic Functions</a></li>
92 <li><a href="#package_lib">Modules</a></li> 92 <li><a href="#package_lib">Modules</a></li>
93 <li><a href="#string_lib">String Manipulation</a></li> 93 <li><a href="#string_lib">String Manipulation</a></li>
94 <li><a href="#table_lib">Table Manipulation</a></li>
94 </ul> 95 </ul>
95 </div> 96 </div>
96 97
97 <hr/> 98 <hr/>
98 99
2655 2656
2656 2657
2657 2658
2658 2659
2659 2660
2660 <h2>6.6 &ndash; <a name="6.6">Table Manipulation</a></h2> 2661 <h3 heading><a name="table_lib">Table Manipulation</a></h3>
2662
2663 <p>
2664 Include this library by:
2665
2666 <pre>
2667 local Table = require "luan:Table"
2668 </pre>
2661 2669
2662 <p> 2670 <p>
2663 This library provides generic functions for table manipulation. 2671 This library provides generic functions for table manipulation.
2664 It provides all its functions inside the table <a name="pdf-table"><code>table</code></a>. 2672 It provides all its functions inside the table <code>Table</code>.
2665 2673
2666 2674
2667 <p> 2675
2668 Remember that, whenever an operation needs the length of a table, 2676 <h4 heading><a name="Table.concat"><code>Table.concat (list [, sep [, i [, j]]])</code></a></h4>
2669 the table must be a proper sequence 2677
2670 or have a <code>__len</code> metamethod (see <a href="#3.4.7">&sect;3.4.7</a>). 2678 <p>
2671 All functions ignore non-numeric keys 2679 Given a list,
2672 in the tables given as arguments.
2673
2674
2675 <p>
2676 <hr><h3><a name="pdf-table.concat"><code>table.concat (list [, sep [, i [, j]]])</code></a></h3>
2677
2678
2679 <p>
2680 Given a list where all elements are strings or numbers,
2681 returns the string <code>list[i]..sep..list[i+1] &middot;&middot;&middot; sep..list[j]</code>. 2680 returns the string <code>list[i]..sep..list[i+1] &middot;&middot;&middot; sep..list[j]</code>.
2682 The default value for <code>sep</code> is the empty string, 2681 The default value for <code>sep</code> is the empty string,
2683 the default for <code>i</code> is 1, 2682 the default for <code>i</code> is 1,
2684 and the default for <code>j</code> is <code>#list</code>. 2683 and the default for <code>j</code> is <code>#list</code>.
2685 If <code>i</code> is greater than <code>j</code>, returns the empty string. 2684 If <code>i</code> is greater than <code>j</code>, returns the empty string.
2686 2685
2687 2686
2688 2687 <h4 heading><a name="Table.copy"><code>Table.copy (tbl [, i [, j]])</code></a></h4>
2689 2688
2690 <p> 2689 <p>
2691 <hr><h3><a name="pdf-table.insert"><code>table.insert (list, [pos,] value)</code></a></h3> 2690 If <code>i</code> is <code>nil</code>, returns a shallow copy of <code>tbl</code>.
2692 2691 Otherwise returns a new table which is a list of the elements <code>tbl[i] &middot;&middot;&middot; tbl[j]</code>.
2692 By default, <code>j</code> is <code>#tbl</code>.
2693
2694
2695
2696 <h4 heading><a name="Table.insert"><code>Table.insert (list, pos, value)</code></a></h4>
2693 2697
2694 <p> 2698 <p>
2695 Inserts element <code>value</code> at position <code>pos</code> in <code>list</code>, 2699 Inserts element <code>value</code> at position <code>pos</code> in <code>list</code>,
2696 shifting up the elements 2700 shifting up the elements
2697 <code>list[pos], list[pos+1], &middot;&middot;&middot;, list[#list]</code>. 2701 <code>list[pos], list[pos+1], &middot;&middot;&middot;, list[#list]</code>.
2698 The default value for <code>pos</code> is <code>#list+1</code>, 2702
2699 so that a call <code>table.insert(t,x)</code> inserts <code>x</code> at the end 2703
2700 of list <code>t</code>. 2704
2701 2705 <h4 heading><a name="Table.pack"><code>Table.pack (&middot;&middot;&middot;)</code></a></h4>
2702
2703
2704
2705 <p>
2706 <hr><h3><a name="pdf-table.move"><code>table.move (a1, f, e, t [,a2])</code></a></h3>
2707
2708
2709 <p>
2710 Moves elements from table <code>a1</code> to table <code>a2</code>.
2711 This function performs the equivalent to the following
2712 multiple assignment:
2713 <code>a2[t],&middot;&middot;&middot; = a1[f],&middot;&middot;&middot;,a1[e]</code>.
2714 The default for <code>a2</code> is <code>a1</code>.
2715 The destination range can overlap with the source range.
2716 Index <code>f</code> must be positive.
2717
2718
2719
2720
2721 <p>
2722 <hr><h3><a name="pdf-table.pack"><code>table.pack (&middot;&middot;&middot;)</code></a></h3>
2723
2724 2706
2725 <p> 2707 <p>
2726 Returns a new table with all parameters stored into keys 1, 2, etc. 2708 Returns a new table with all parameters stored into keys 1, 2, etc.
2727 and with a field "<code>n</code>" with the total number of parameters. 2709 and with a field "<code>n</code>" with the total number of parameters.
2728 Note that the resulting table may not be a sequence. 2710 Note that the resulting table may not be a sequence.
2729 2711
2730 2712
2731 2713
2732 2714
2733 <p> 2715 <h4 heading><a name="Table.remove"><code>Table.remove (list, pos)</code></a></h4>
2734 <hr><h3><a name="pdf-table.remove"><code>table.remove (list [, pos])</code></a></h3>
2735 2716
2736 2717
2737 <p> 2718 <p>
2738 Removes from <code>list</code> the element at position <code>pos</code>, 2719 Removes from <code>list</code> the element at position <code>pos</code>,
2739 returning the value of the removed element. 2720 returning the value of the removed element.
2744 The index <code>pos</code> can also be 0 when <code>#list</code> is 0, 2725 The index <code>pos</code> can also be 0 when <code>#list</code> is 0,
2745 or <code>#list + 1</code>; 2726 or <code>#list + 1</code>;
2746 in those cases, the function erases the element <code>list[pos]</code>. 2727 in those cases, the function erases the element <code>list[pos]</code>.
2747 2728
2748 2729
2749 <p> 2730
2750 The default value for <code>pos</code> is <code>#list</code>, 2731
2751 so that a call <code>table.remove(l)</code> removes the last element 2732 <h4 heading><a name="Table.sort"><code>Table.sort (list [, comp])</code></a></h4>
2752 of list <code>l</code>.
2753
2754
2755
2756
2757 <p>
2758 <hr><h3><a name="pdf-table.sort"><code>table.sort (list [, comp])</code></a></h3>
2759
2760 2733
2761 <p> 2734 <p>
2762 Sorts list elements in a given order, <em>in-place</em>, 2735 Sorts list elements in a given order, <em>in-place</em>,
2763 from <code>list[1]</code> to <code>list[#list]</code>. 2736 from <code>list[1]</code> to <code>list[#list]</code>.
2764 If <code>comp</code> is given, 2737 If <code>comp</code> is given,
2767 before the second in the final order 2740 before the second in the final order
2768 (so that <code>not comp(list[i+1],list[i])</code> will be true after the sort). 2741 (so that <code>not comp(list[i+1],list[i])</code> will be true after the sort).
2769 If <code>comp</code> is not given, 2742 If <code>comp</code> is not given,
2770 then the standard Lua operator <code>&lt;</code> is used instead. 2743 then the standard Lua operator <code>&lt;</code> is used instead.
2771 2744
2772
2773 <p> 2745 <p>
2774 The sort algorithm is not stable; 2746 The sort algorithm is not stable;
2775 that is, elements considered equal by the given order 2747 that is, elements considered equal by the given order
2776 may have their relative positions changed by the sort. 2748 may have their relative positions changed by the sort.
2777 2749
2778 2750
2779 2751
2780 2752 <h4 heading><a name="Table.unpack"><code>Table.unpack (list [, i [, j]])</code></a></h4>
2781 <p>
2782 <hr><h3><a name="pdf-table.unpack"><code>table.unpack (list [, i [, j]])</code></a></h3>
2783
2784 2753
2785 <p> 2754 <p>
2786 Returns the elements from the given list. 2755 Returns the elements from the given list.
2787 This function is equivalent to 2756 This function is equivalent to
2788 2757
2789 <pre> 2758 <pre>
2790 return list[i], list[i+1], &middot;&middot;&middot;, list[j] 2759 return list[i], list[i+1], &middot;&middot;&middot;, list[j]
2791 </pre><p> 2760 </pre>
2761
2762 <p>
2792 By default, <code>i</code> is&nbsp;1 and <code>j</code> is <code>#list</code>. 2763 By default, <code>i</code> is&nbsp;1 and <code>j</code> is <code>#list</code>.
2793 2764
2794 2765
2795 2766
2796 2767