1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900
|
<!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>Penlight Documentation</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>Penlight</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="#Lua_____Compatible_Functions">Lua 5.2 Compatible Functions</a></li>
</ul>
<h2>Modules</h2>
<ul>
<li><a href="../modules/pl.html">pl</a></li>
<li><a href="../modules/pl.Date.html">pl.Date</a></li>
<li><a href="../modules/pl.List.html">pl.List</a></li>
<li><a href="../modules/pl.Map.html">pl.Map</a></li>
<li><a href="../modules/pl.MultiMap.html">pl.MultiMap</a></li>
<li><a href="../modules/pl.OrderedMap.html">pl.OrderedMap</a></li>
<li><a href="../modules/pl.Set.html">pl.Set</a></li>
<li><a href="../modules/pl.app.html">pl.app</a></li>
<li><a href="../modules/pl.array2d.html">pl.array2d</a></li>
<li><a href="../modules/pl.class.html">pl.class</a></li>
<li><a href="../modules/pl.comprehension.html">pl.comprehension</a></li>
<li><a href="../modules/pl.config.html">pl.config</a></li>
<li><a href="../modules/pl.data.html">pl.data</a></li>
<li><a href="../modules/pl.dir.html">pl.dir</a></li>
<li><a href="../modules/pl.file.html">pl.file</a></li>
<li><a href="../modules/pl.func.html">pl.func</a></li>
<li><a href="../modules/pl.input.html">pl.input</a></li>
<li><a href="../modules/pl.lapp.html">pl.lapp</a></li>
<li><a href="../modules/pl.lexer.html">pl.lexer</a></li>
<li><a href="../modules/pl.luabalanced.html">pl.luabalanced</a></li>
<li><a href="../modules/pl.operator.html">pl.operator</a></li>
<li><a href="../modules/pl.path.html">pl.path</a></li>
<li><a href="../modules/pl.permute.html">pl.permute</a></li>
<li><a href="../modules/pl.pretty.html">pl.pretty</a></li>
<li><a href="../modules/pl.seq.html">pl.seq</a></li>
<li><a href="../modules/pl.sip.html">pl.sip</a></li>
<li><a href="../modules/pl.strict.html">pl.strict</a></li>
<li><a href="../modules/pl.stringio.html">pl.stringio</a></li>
<li><a href="../modules/pl.stringx.html">pl.stringx</a></li>
<li><a href="../modules/pl.tablex.html">pl.tablex</a></li>
<li><a href="../modules/pl.template.html">pl.template</a></li>
<li><a href="../modules/pl.test.html">pl.test</a></li>
<li><a href="../modules/pl.text.html">pl.text</a></li>
<li><strong>pl.utils</strong></li>
<li><a href="../modules/pl.xml.html">pl.xml</a></li>
</ul>
<h2>Topics</h2>
<ul>
<li><a href="../topics/01-introduction.md.html">01-introduction.md</a></li>
<li><a href="../topics/02-arrays.md.html">02-arrays.md</a></li>
<li><a href="../topics/03-strings.md.html">03-strings.md</a></li>
<li><a href="../topics/04-paths.md.html">04-paths.md</a></li>
<li><a href="../topics/05-dates.md.html">05-dates.md</a></li>
<li><a href="../topics/06-data.md.html">06-data.md</a></li>
<li><a href="../topics/07-functional.md.html">07-functional.md</a></li>
<li><a href="../topics/08-additional.md.html">08-additional.md</a></li>
<li><a href="../topics/09-discussion.md.html">09-discussion.md</a></li>
</ul>
<h2>Examples</h2>
<ul>
<li><a href="../examples/seesubst.lua.html">seesubst.lua</a></li>
<li><a href="../examples/sipscan.lua.html">sipscan.lua</a></li>
<li><a href="../examples/symbols.lua.html">symbols.lua</a></li>
<li><a href="../examples/test-cmp.lua.html">test-cmp.lua</a></li>
<li><a href="../examples/test-data.lua.html">test-data.lua</a></li>
<li><a href="../examples/test-listcallbacks.lua.html">test-listcallbacks.lua</a></li>
<li><a href="../examples/test-pretty.lua.html">test-pretty.lua</a></li>
<li><a href="../examples/test-symbols.lua.html">test-symbols.lua</a></li>
<li><a href="../examples/testapp.lua.html">testapp.lua</a></li>
<li><a href="../examples/testclone.lua.html">testclone.lua</a></li>
<li><a href="../examples/testconfig.lua.html">testconfig.lua</a></li>
<li><a href="../examples/testglobal.lua.html">testglobal.lua</a></li>
<li><a href="../examples/testinputfields.lua.html">testinputfields.lua</a></li>
<li><a href="../examples/testinputfields2.lua.html">testinputfields2.lua</a></li>
<li><a href="../examples/testxml.lua.html">testxml.lua</a></li>
<li><a href="../examples/which.lua.html">which.lua</a></li>
</ul>
</div>
<div id="content">
<h1>Module <code>pl.utils</code></h1>
<p>Generally useful routines.</p>
<p> See <a href="../topics/01-introduction.md.html#Generally_useful_functions_">the Guide</a>.</p>
<h2><a href="#Functions">Functions</a></h2>
<table class="function_list">
<tr>
<td class="name" nowrap><a href="#quit">quit (code, ...)</a></td>
<td class="summary">end this program gracefully.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#printf">printf (fmt, ...)</a></td>
<td class="summary">print an arbitrary number of arguments using a format.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#fprintf">fprintf (f, fmt, ...)</a></td>
<td class="summary">write an arbitrary number of arguments to a file using a format.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#import">import (t, T)</a></td>
<td class="summary">take a table and ‘inject’ it into the local namespace.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#escape">escape (s)</a></td>
<td class="summary">escape any ‘magic’ characters in a string</td>
</tr>
<tr>
<td class="name" nowrap><a href="#choose">choose (cond, value1, value2)</a></td>
<td class="summary">return either of two values, depending on a condition.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#readfile">readfile (filename, is_bin)</a></td>
<td class="summary">return the contents of a file as a string</td>
</tr>
<tr>
<td class="name" nowrap><a href="#writefile">writefile (filename, str)</a></td>
<td class="summary">write a string to a file</td>
</tr>
<tr>
<td class="name" nowrap><a href="#readlines">readlines (filename)</a></td>
<td class="summary">return the contents of a file as a list of lines</td>
</tr>
<tr>
<td class="name" nowrap><a href="#split">split (s, re, plain, n)</a></td>
<td class="summary">split a string into a list of strings separated by a delimiter.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#splitv">splitv (s, re)</a></td>
<td class="summary">split a string into a number of values.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#execute">execute (cmd)</a></td>
<td class="summary">execute a shell command.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#memoize">memoize (func)</a></td>
<td class="summary">‘memoize’ a function (cache returned value for next call).</td>
</tr>
<tr>
<td class="name" nowrap><a href="#is_callable">is_callable (obj)</a></td>
<td class="summary">is the object either a function or a callable object?.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#is_type">is_type (obj, tp)</a></td>
<td class="summary">is the object of the specified type?.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#type">type (obj)</a></td>
<td class="summary">a string representation of a type.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#is_integer">is_integer (x)</a></td>
<td class="summary">is this number an integer?</td>
</tr>
<tr>
<td class="name" nowrap><a href="#add_function_factory">add_function_factory (mt, fun)</a></td>
<td class="summary">associate a function factory with a type.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#string_lambda">string_lambda (lf)</a></td>
<td class="summary">an anonymous function as a string.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#function_arg">function_arg (idx, f, msg)</a></td>
<td class="summary">process a function argument.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#bind1">bind1 (fn, p)</a></td>
<td class="summary">bind the first argument of the function to a value.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#bind2">bind2 (fn, p)</a></td>
<td class="summary">bind the second argument of the function to a value.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#assert_arg">assert_arg (n, val, tp, verify, msg, lev)</a></td>
<td class="summary">assert that the given argument is in fact of the correct type.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#assert_string">assert_string (n, val)</a></td>
<td class="summary">assert the common case that the argument is a string.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#on_error">on_error (mode)</a></td>
<td class="summary">control the error strategy used by Penlight.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#raise">raise (err)</a></td>
<td class="summary">used by Penlight functions to return errors.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#load">load (code, name, mode, env)</a></td>
<td class="summary">load a code string or bytecode chunk.</td>
</tr>
</table>
<h2><a href="#Lua_____Compatible_Functions">Lua 5.2 Compatible Functions</a></h2>
<table class="function_list">
<tr>
<td class="name" nowrap><a href="#table.pack">table.pack (...)</a></td>
<td class="summary">pack an argument list into a table.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#package.searchpath">package.searchpath (mod, path)</a></td>
<td class="summary">return the full path where a Lua module name would be matched.</td>
</tr>
</table>
<br/>
<br/>
<h2><a name="Functions"></a>Functions</h2>
<dl class="function">
<dt>
<a name = "quit"></a>
<strong>quit (code, ...)</strong>
</dt>
<dd>
end this program gracefully.
<h3>Parameters:</h3>
<ul>
<li><code><em>code</em></code>: The exit code or a message to be printed</li>
<li><code><em>...</em></code>: extra arguments for message’s format'</li>
</ul>
<h3>see also:</h3>
<ul>
<a href="../modules/pl.utils.html#fprintf">utils.fprintf</a>
</ul>
</dd>
<dt>
<a name = "printf"></a>
<strong>printf (fmt, ...)</strong>
</dt>
<dd>
print an arbitrary number of arguments using a format.
<h3>Parameters:</h3>
<ul>
<li><code><em>fmt</em></code>: The format (see string.format)</li>
<li><code><em>...</em></code>: Extra arguments for format</li>
</ul>
</dd>
<dt>
<a name = "fprintf"></a>
<strong>fprintf (f, fmt, ...)</strong>
</dt>
<dd>
write an arbitrary number of arguments to a file using a format.
<h3>Parameters:</h3>
<ul>
<li><code><em>f</em></code>: File handle to write to.</li>
<li><code><em>fmt</em></code>: The format (see string.format).</li>
<li><code><em>...</em></code>: Extra arguments for format</li>
</ul>
</dd>
<dt>
<a name = "import"></a>
<strong>import (t, T)</strong>
</dt>
<dd>
take a table and ‘inject’ it into the local namespace.
<h3>Parameters:</h3>
<ul>
<li><code><em>t</em></code>: The Table</li>
<li><code><em>T</em></code>: An optional destination table (defaults to callers environment)</li>
</ul>
</dd>
<dt>
<a name = "escape"></a>
<strong>escape (s)</strong>
</dt>
<dd>
escape any ‘magic’ characters in a string
<h3>Parameters:</h3>
<ul>
<li><code><em>s</em></code>: The input string</li>
</ul>
</dd>
<dt>
<a name = "choose"></a>
<strong>choose (cond, value1, value2)</strong>
</dt>
<dd>
return either of two values, depending on a condition.
<h3>Parameters:</h3>
<ul>
<li><code><em>cond</em></code>: A condition</li>
<li><code><em>value1</em></code>: Value returned if cond is true</li>
<li><code><em>value2</em></code>: Value returned if cond is false (can be optional)</li>
</ul>
</dd>
<dt>
<a name = "readfile"></a>
<strong>readfile (filename, is_bin)</strong>
</dt>
<dd>
return the contents of a file as a string
<h3>Parameters:</h3>
<ul>
<li><code><em>filename</em></code>: The file path</li>
<li><code><em>is_bin</em></code>: open in binary mode</li>
</ul>
<h3>Returns:</h3>
<ol>
file contents
</ol>
</dd>
<dt>
<a name = "writefile"></a>
<strong>writefile (filename, str)</strong>
</dt>
<dd>
write a string to a file
<h3>Parameters:</h3>
<ul>
<li><code><em>filename</em></code>: The file path</li>
<li><code><em>str</em></code>: The string</li>
</ul>
<h3>Returns:</h3>
<ol>
<li>true or nil</li>
<li>error message</li>
</ol>
<h3>Raises:</h3>
error if filename or str aren’t strings
</dd>
<dt>
<a name = "readlines"></a>
<strong>readlines (filename)</strong>
</dt>
<dd>
return the contents of a file as a list of lines
<h3>Parameters:</h3>
<ul>
<li><code><em>filename</em></code>: The file path</li>
</ul>
<h3>Returns:</h3>
<ol>
file contents as a table
</ol>
<h3>Raises:</h3>
errror if filename is not a string
</dd>
<dt>
<a name = "split"></a>
<strong>split (s, re, plain, n)</strong>
</dt>
<dd>
split a string into a list of strings separated by a delimiter.
<h3>Parameters:</h3>
<ul>
<li><code><em>s</em></code>: The input string</li>
<li><code><em>re</em></code>: A Lua string pattern; defaults to ‘%s+’</li>
<li><code><em>plain</em></code>: don’t use Lua patterns</li>
<li><code><em>n</em></code>: optional maximum number of splits</li>
</ul>
<h3>Returns:</h3>
<ol>
a list-like table
</ol>
<h3>Raises:</h3>
error if s is not a string
</dd>
<dt>
<a name = "splitv"></a>
<strong>splitv (s, re)</strong>
</dt>
<dd>
split a string into a number of values.
<h3>Parameters:</h3>
<ul>
<li><code><em>s</em></code>: the string</li>
<li><code><em>re</em></code>: the delimiter, default space</li>
</ul>
<h3>Usage:</h3>
<ul>
<pre class="example">first,next = splitv('jane:doe',':')</pre>
</ul>
<h3>Returns:</h3>
<ol>
n values
</ol>
<h3>see also:</h3>
<ul>
<a href="../modules/pl.utils.html#split">split</a>
</ul>
</dd>
<dt>
<a name = "execute"></a>
<strong>execute (cmd)</strong>
</dt>
<dd>
execute a shell command.
This is a compatibility function that returns the same for Lua 5.1 and Lua 5.2
<h3>Parameters:</h3>
<ul>
<li><code><em>cmd</em></code>: a shell command</li>
</ul>
<h3>Returns:</h3>
<ol>
<li>true if successful</li>
<li>actual return code</li>
</ol>
</dd>
<dt>
<a name = "memoize"></a>
<strong>memoize (func)</strong>
</dt>
<dd>
‘memoize’ a function (cache returned value for next call).
This is useful if you have a function which is relatively expensive,
but you don’t know in advance what values will be required, so
building a table upfront is wasteful/impossible.
<h3>Parameters:</h3>
<ul>
<li><code><em>func</em></code>: a function of at least one argument</li>
</ul>
<h3>Returns:</h3>
<ol>
a function with at least one argument, which is used as the key.
</ol>
</dd>
<dt>
<a name = "is_callable"></a>
<strong>is_callable (obj)</strong>
</dt>
<dd>
is the object either a function or a callable object?.
<h3>Parameters:</h3>
<ul>
<li><code><em>obj</em></code>: Object to check.</li>
</ul>
</dd>
<dt>
<a name = "is_type"></a>
<strong>is_type (obj, tp)</strong>
</dt>
<dd>
is the object of the specified type?.
If the type is a string, then use type, otherwise compare with metatable
<h3>Parameters:</h3>
<ul>
<li><code><em>obj</em></code>: An object to check</li>
<li><code><em>tp</em></code>: String of what type it should be</li>
</ul>
</dd>
<dt>
<a name = "type"></a>
<strong>type (obj)</strong>
</dt>
<dd>
a string representation of a type.
For tables with metatables, we assume that the metatable has a <code>_name</code>
field. Knows about Lua file objects.
<h3>Parameters:</h3>
<ul>
<li><code><em>obj</em></code>: an object</li>
</ul>
<h3>Returns:</h3>
<ol>
a string like ‘number’, ‘table’ or ‘List’
</ol>
</dd>
<dt>
<a name = "is_integer"></a>
<strong>is_integer (x)</strong>
</dt>
<dd>
is this number an integer?
<h3>Parameters:</h3>
<ul>
<li><code><em>x</em></code>: a number</li>
</ul>
<h3>Raises:</h3>
error if x is not a number
</dd>
<dt>
<a name = "add_function_factory"></a>
<strong>add_function_factory (mt, fun)</strong>
</dt>
<dd>
associate a function factory with a type.
A function factory takes an object of the given type and
returns a function for evaluating it
<h3>Parameters:</h3>
<ul>
<li><code><em>mt</em></code>: metatable</li>
<li><code><em>fun</em></code>: a callable that returns a function</li>
</ul>
</dd>
<dt>
<a name = "string_lambda"></a>
<strong>string_lambda (lf)</strong>
</dt>
<dd>
an anonymous function as a string. This string is either of the form
‘|args| expression’ or is a function of one argument, ‘_’
<h3>Parameters:</h3>
<ul>
<li><code><em>lf</em></code>: function as a string</li>
</ul>
<h3>Usage:</h3>
<ul>
<li><pre class="example">string_lambda '|x|x+1' (2) == 3</pre></li>
<li><pre class="example">string_lambda '_+1 (2) == 3</pre></li>
</ul>
<h3>Returns:</h3>
<ol>
a function
</ol>
</dd>
<dt>
<a name = "function_arg"></a>
<strong>function_arg (idx, f, msg)</strong>
</dt>
<dd>
process a function argument.
This is used throughout Penlight and defines what is meant by a function:
Something that is callable, or an operator string as defined by <code>pl.operator</code>,
such as ‘>’ or ‘#’. If a function factory has been registered for the type, it will
be called to get the function.
<h3>Parameters:</h3>
<ul>
<li><code><em>idx</em></code>: argument index</li>
<li><code><em>f</em></code>: a function, operator string, or callable object</li>
<li><code><em>msg</em></code>: optional error message</li>
</ul>
<h3>Returns:</h3>
<ol>
a callable
</ol>
<h3>Raises:</h3>
if idx is not a number or if f is not callable
<h3>see also:</h3>
<ul>
<a href="../modules/pl.utils.html#is_callable">utils.is_callable</a>
</ul>
</dd>
<dt>
<a name = "bind1"></a>
<strong>bind1 (fn, p)</strong>
</dt>
<dd>
bind the first argument of the function to a value.
<h3>Parameters:</h3>
<ul>
<li><code><em>fn</em></code>: a function of at least two values (may be an operator string)</li>
<li><code><em>p</em></code>: a value</li>
</ul>
<h3>Returns:</h3>
<ol>
a function such that f(x) is fn(p,x)
</ol>
<h3>Raises:</h3>
same as <a href="../modules/pl.utils.html#function_arg">function_arg</a>
<h3>see also:</h3>
<ul>
<a href="../modules/pl.func.html#curry">pl.func.curry</a>
</ul>
</dd>
<dt>
<a name = "bind2"></a>
<strong>bind2 (fn, p)</strong>
</dt>
<dd>
bind the second argument of the function to a value.
<h3>Parameters:</h3>
<ul>
<li><code><em>fn</em></code>: a function of at least two values (may be an operator string)</li>
<li><code><em>p</em></code>: a value</li>
</ul>
<h3>Returns:</h3>
<ol>
a function such that f(x) is fn(x,p)
</ol>
<h3>Raises:</h3>
same as <a href="../modules/pl.utils.html#function_arg">function_arg</a>
</dd>
<dt>
<a name = "assert_arg"></a>
<strong>assert_arg (n, val, tp, verify, msg, lev)</strong>
</dt>
<dd>
assert that the given argument is in fact of the correct type.
<h3>Parameters:</h3>
<ul>
<li><code><em>n</em></code>: argument index</li>
<li><code><em>val</em></code>: the value</li>
<li><code><em>tp</em></code>: the type</li>
<li><code><em>verify</em></code>: an optional verfication function</li>
<li><code><em>msg</em></code>: an optional custom message</li>
<li><code><em>lev</em></code>: optional stack position for trace, default 2</li>
</ul>
<h3>Usage:</h3>
<ul>
<li><pre class="example">assert_arg(1,t,'table')</pre></li>
<li><pre class="example">assert_arg(n,val,'string',path.isdir,'not a directory')</pre></li>
</ul>
<h3>Raises:</h3>
if the argument n is not the correct type
</dd>
<dt>
<a name = "assert_string"></a>
<strong>assert_string (n, val)</strong>
</dt>
<dd>
assert the common case that the argument is a string.
<h3>Parameters:</h3>
<ul>
<li><code><em>n</em></code>: argument index</li>
<li><code><em>val</em></code>: a value that must be a string</li>
</ul>
<h3>Raises:</h3>
val must be a string
</dd>
<dt>
<a name = "on_error"></a>
<strong>on_error (mode)</strong>
</dt>
<dd>
control the error strategy used by Penlight.
Controls how <code>utils.raise</code> works; the default is for it
to return nil and the error string, but if the mode is ‘error’ then
it will throw an error. If mode is ‘quit’ it will immediately terminate
the program.
<h3>Parameters:</h3>
<ul>
<li><code><em>mode</em></code>: <ul>
<li>either ‘default’, ‘quit’ or ‘error’</li>
</ul>
</li>
</ul>
<h3>see also:</h3>
<ul>
<a href="../modules/pl.utils.html#raise">utils.raise</a>
</ul>
</dd>
<dt>
<a name = "raise"></a>
<strong>raise (err)</strong>
</dt>
<dd>
used by Penlight functions to return errors. Its global behaviour is controlled
by <code>utils.on_error</code>
<h3>Parameters:</h3>
<ul>
<li><code><em>err</em></code>: the error string.</li>
</ul>
<h3>see also:</h3>
<ul>
<a href="../modules/pl.utils.html#on_error">utils.on_error</a>
</ul>
</dd>
<dt>
<a name = "load"></a>
<strong>load (code, name, mode, env)</strong>
</dt>
<dd>
load a code string or bytecode chunk.
<h3>Parameters:</h3>
<ul>
<li><code><em>code</em></code>: Lua code as a string or bytecode</li>
<li><code><em>name</em></code>: for source errors</li>
<li><code><em>mode</em></code>: kind of chunk, ’t' for text, ‘b’ for bytecode, ‘bt’ for all (default)</li>
<li><code><em>env</em></code>: the environment for the new chunk (default nil)</li>
</ul>
<h3>Returns:</h3>
<ol>
<li>compiled chunk</li>
<li>error message (chunk is nil)</li>
</ol>
</dd>
</dl>
<h2><a name="Lua_____Compatible_Functions"></a>Lua 5.2 Compatible Functions</h2>
<dl class="function">
<dt>
<a name = "table.pack"></a>
<strong>table.pack (...)</strong>
</dt>
<dd>
pack an argument list into a table.
<h3>Parameters:</h3>
<ul>
<li><code><em>...</em></code>: any arguments</li>
</ul>
<h3>Returns:</h3>
<ol>
<li>a table with field n set to the length</li>
<li>the length</li>
</ol>
</dd>
<dt>
<a name = "package.searchpath"></a>
<strong>package.searchpath (mod, path)</strong>
</dt>
<dd>
return the full path where a Lua module name would be matched.
<h3>Parameters:</h3>
<ul>
<li><code><em>mod</em></code>: module name, possibly dotted</li>
<li><code><em>path</em></code>: a path in the same form as package.path or package.cpath</li>
</ul>
<h3>see also:</h3>
<ul>
<a href="../modules/pl.path.html#package_path">path.package_path</a>
</ul>
</dd>
</dl>
</div> <!-- id="content" -->
</div> <!-- id="main" -->
<div id="about">
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.2</a></i>
</div> <!-- id="about" -->
</div> <!-- id="container" -->
</body>
</html>
|