comparison website/src/manual.html @ 382:8557581740db

added tutorial
author Franklin Schmidt <fschmidt@gmail.com>
date Wed, 22 Apr 2015 20:38:48 -0600
parents 6c6c3537035e
children
comparison
equal deleted inserted replaced
381:83efd1e3685c 382:8557581740db
297 Note that queries for metamethods are always raw; 297 Note that queries for metamethods are always raw;
298 the access to a metamethod does not invoke other metamethods. 298 the access to a metamethod does not invoke other metamethods.
299 You can emulate how Luan queries a metamethod for an object <tt>obj</tt> 299 You can emulate how Luan queries a metamethod for an object <tt>obj</tt>
300 with the following code: 300 with the following code:
301 301
302 <tt><pre> 302 <p><tt><pre>
303 raw_get(get_metatable(obj) or {}, "__" .. event_name) 303 raw_get(get_metatable(obj) or {}, "__" .. event_name)
304 304 </pre></tt></p>
305 </pre></tt>
306 305
307 <p> 306 <p>
308 Here are the events: 307 Here are the events:
309 308
310 <ul> 309 <ul>
527 <p> 526 <p>
528 The following <i>keywords</i> are reserved 527 The following <i>keywords</i> are reserved
529 and cannot be used as names: 528 and cannot be used as names:
530 529
531 530
532 <pre> 531 <p><pre>
533 and break do else elseif end 532 and break do else elseif end
534 false for function goto if in 533 false for function goto if in
535 local nil not or repeat return 534 local nil not or repeat return
536 then true until while 535 then true until while
537 </pre> 536 </pre></p>
538 537
539 <p> 538 <p>
540 Luan is a case-sensitive language: 539 Luan is a case-sensitive language:
541 <tt>and</tt> is a reserved word, but <tt>And</tt> and <tt>AND</tt> 540 <tt>and</tt> is a reserved word, but <tt>And</tt> and <tt>AND</tt>
542 are two different, valid names. 541 are two different, valid names.
543 542
544 543
545 <p> 544 <p>
546 The following strings denote other tokens: 545 The following strings denote other tokens:
547 546
548 <pre> 547 <p><pre>
549 + - * / % ^ # 548 + - * / % ^ #
550 &amp; ~ | &lt;&lt; &gt;&gt; // 549 &amp; ~ | &lt;&lt; &gt;&gt; //
551 == ~= &lt;= &gt;= &lt; &gt; = 550 == ~= &lt;= &gt;= &lt; &gt; =
552 ( ) { } [ ] :: 551 ( ) { } [ ] ::
553 ; : , . .. ... 552 ; : , . .. ...
554 553 </pre></p>
555 </pre>
556 554
557 <p> 555 <p>
558 <i>Literal strings</i> 556 <i>Literal strings</i>
559 can be delimited by matching single or double quotes, 557 can be delimited by matching single or double quotes,
560 and can contain the following C-like escape sequences: 558 and can contain the following C-like escape sequences:
629 when the opening long bracket is immediately followed by a newline, 627 when the opening long bracket is immediately followed by a newline,
630 the newline is not included in the string. 628 the newline is not included in the string.
631 As an example 629 As an example
632 the five literal strings below denote the same string: 630 the five literal strings below denote the same string:
633 631
634 <pre> 632 <p><pre>
635 a = 'alo\n123"' 633 a = 'alo\n123"'
636 a = "alo\n123\"" 634 a = "alo\n123\""
637 a = '\97lo\10\04923"' 635 a = '\97lo\10\04923"'
638 a = [[alo 636 a = [[alo
639 123"]] 637 123"]]
640 a = [==[ 638 a = [==[
641 alo 639 alo
642 123"]==] 640 123"]==]
643 641 </pre></p>
644 </pre>
645 642
646 <p> 643 <p>
647 A <i>numerical constant</i> (or <i>numeral</i>) 644 A <i>numerical constant</i> (or <i>numeral</i>)
648 can be written with an optional fractional part 645 can be written with an optional fractional part
649 and an optional decimal exponent, 646 and an optional decimal exponent,
656 A numeric constant with a fractional dot or an exponent 653 A numeric constant with a fractional dot or an exponent
657 denotes a float; 654 denotes a float;
658 otherwise it denotes an integer. 655 otherwise it denotes an integer.
659 Examples of valid integer constants are 656 Examples of valid integer constants are
660 657
661 <pre> 658 <p><pre>
662 3 345 0xff 0xBEBADA 659 3 345 0xff 0xBEBADA
663 660 </pre></p>
664 </pre><p> 661
662 <p>
665 Examples of valid float constants are 663 Examples of valid float constants are
666 664
667 <pre> 665 <p><pre>
668 3.0 3.1416 314.16e-2 0.31416E1 34e1 666 3.0 3.1416 314.16e-2 0.31416E1 34e1
669 0x0.1E 0xA23p-4 0X1.921FB54442D18P+1 667 0x0.1E 0xA23p-4 0X1.921FB54442D18P+1
670 668 </pre></p>
671 </pre>
672 669
673 <p> 670 <p>
674 A <i>comment</i> starts with a double hyphen (<tt>--</tt>) 671 A <i>comment</i> starts with a double hyphen (<tt>--</tt>)
675 anywhere outside a string. 672 anywhere outside a string.
676 If the text immediately after <tt>--</tt> is not an opening long bracket, 673 If the text immediately after <tt>--</tt> is not an opening long bracket,
695 <p> 692 <p>
696 A single name can denote a global variable or a local variable 693 A single name can denote a global variable or a local variable
697 (or a function's formal parameter, 694 (or a function's formal parameter,
698 which is a particular kind of local variable): 695 which is a particular kind of local variable):
699 696
700 <pre> 697 <p><pre>
701 var ::= Name 698 var ::= Name
702 699 </pre></p>
703 </pre><p> 700
701 <p>
704 Name denotes identifiers, as defined in <a href="#3.1">&sect;3.1</a>. 702 Name denotes identifiers, as defined in <a href="#3.1">&sect;3.1</a>.
705 703
706 704
707 <p> 705 <p>
708 Any variable name is assumed to be global unless explicitly declared 706 Any variable name is assumed to be global unless explicitly declared
717 715
718 716
719 <p> 717 <p>
720 Square brackets are used to index a table: 718 Square brackets are used to index a table:
721 719
722 <pre> 720 <p><pre>
723 var ::= prefixexp &lsquo;<b>[</b>&rsquo; exp &lsquo;<b>]</b>&rsquo; 721 var ::= prefixexp &lsquo;<b>[</b>&rsquo; exp &lsquo;<b>]</b>&rsquo;
724 722 </pre></p>
725 </pre><p> 723
724 <p>
726 The meaning of accesses to table fields can be changed via metatables. 725 The meaning of accesses to table fields can be changed via metatables.
727 An access to an indexed variable <tt>t[i]</tt> is equivalent to 726 An access to an indexed variable <tt>t[i]</tt> is equivalent to
728 a call <tt>gettable_event(t,i)</tt>. 727 a call <tt>gettable_event(t,i)</tt>.
729 (See <a href="#2.4">&sect;2.4</a> for a complete description of the 728 (See <a href="#2.4">&sect;2.4</a> for a complete description of the
730 <tt>gettable_event</tt> function. 729 <tt>gettable_event</tt> function.
734 733
735 <p> 734 <p>
736 The syntax <tt>var.Name</tt> is just syntactic sugar for 735 The syntax <tt>var.Name</tt> is just syntactic sugar for
737 <tt>var["Name"]</tt>: 736 <tt>var["Name"]</tt>:
738 737
739 <pre> 738 <p><pre>
740 var ::= prefixexp &lsquo;<b>.</b>&rsquo; Name 739 var ::= prefixexp &lsquo;<b>.</b>&rsquo; Name
741 740 </pre></p>
742 </pre>
743 741
744 <p> 742 <p>
745 An access to a global variable <tt>x</tt> 743 An access to a global variable <tt>x</tt>
746 is equivalent to <tt>_ENV.x</tt>. 744 is equivalent to <tt>_ENV.x</tt>.
747 Due to the way that chunks are compiled, 745 Due to the way that chunks are compiled,