@@ -55,7 +55,6 @@ Lua means "moon" in Portuguese and is pronounced LOO-ah.
55
55
56
56
==============================================================================
57
57
2 THE LANGUAGE *luaref-language*
58
- ==============================================================================
59
58
60
59
This section describes the lexis, the syntax, and the semantics of Lua. In
61
60
other words, this section describes which tokens are valid, how they can be
@@ -450,21 +449,22 @@ through an arithmetic progression. It has the following syntax:
450
449
<
451
450
The `block` is repeated for `name` starting at the value of the first `exp ` , until
452
451
it passes the second `exp ` by steps of the third `exp ` . More precisely,
453
- a `for ` statement like
452
+ a `for ` statement like >
454
453
455
- ` for var =` ` e1, e2, e3` ` do ` ` block` ` end `
454
+ for var = e1, e2, e3 do block end
456
455
457
- is equivalent to the code:
456
+ < is equivalent to the code: >
458
457
459
- `do `
460
- `local` `var, limit, step` `= tonumber(e1), tonumber(e2), tonumber(e3)`
461
- `if not (` `var ` `and ` `limit` `and ` `step` `) then error() end`
462
- `while (` `step` `>0 and` `var ` `<= ` `limit` `)`
463
- `or (` `step` `<=0 and` `var ` `>= ` `limit` `) do`
464
- `block`
465
- `var ` `= ` `var ` `+ ` `step`
466
- `end `
467
- `end `
458
+ do
459
+ local var, limit, step = tonumber(e1), tonumber(e2), tonumber(e3)
460
+ if not ( var and limit and step ) then error() end
461
+ while ( step >0 and var <= limit )
462
+ or ( step <=0 and var >= limit ) do
463
+ block
464
+ var = var + step
465
+ end
466
+ end
467
+ <
468
468
469
469
Note the following:
470
470
@@ -490,18 +490,18 @@ A `for` statement like
490
490
491
491
`for ` `var1, ..., varn` `in ` `explist` `do ` `block` `end `
492
492
493
- is equivalent to the code:
494
-
495
- `do `
496
- `local` `f, s, var` `= ` `explist`
497
- `while true do`
498
- `local` `var1, ..., varn` `= ` `f(s, var)`
499
- `var ` `= ` `var1`
500
- `if ` `var ` `== nil then break end`
501
- `block`
502
- `end `
503
- `end `
493
+ is equivalent to the code: >
504
494
495
+ do
496
+ local f, s, var = explist
497
+ while true do
498
+ local var1, ..., varn = f(s, var)
499
+ var = var1
500
+ if var == nil then break end
501
+ block
502
+ end
503
+ end
504
+ <
505
505
Note the following:
506
506
507
507
- `explist` is evaluated only once. Its results are an iterator function,
@@ -1871,25 +1871,25 @@ lua_gc *lua_gc()*
1871
1871
This function performs several tasks, according to the value of the
1872
1872
parameter `what` :
1873
1873
1874
- `LUA_GCSTOP` stops the garbage collector.
1875
- `LUA_GCRESTART` restarts the garbage collector.
1876
- `LUA_GCCOLLECT` performs a full garbage-collection cycle.
1877
- `LUA_GCCOUNT` returns the current amount of memory (in Kbytes) in
1874
+ - `LUA_GCSTOP` stops the garbage collector.
1875
+ - `LUA_GCRESTART` restarts the garbage collector.
1876
+ - `LUA_GCCOLLECT` performs a full garbage-collection cycle.
1877
+ - `LUA_GCCOUNT` returns the current amount of memory (in Kbytes) in
1878
1878
use by Lua.
1879
- `LUA_GCCOUNTB` returns the remainder of dividing the current
1879
+ - `LUA_GCCOUNTB` returns the remainder of dividing the current
1880
1880
amount of bytes of memory in use by Lua by 1024.
1881
- `LUA_GCSTEP` performs an incremental step of garbage collection.
1881
+ - `LUA_GCSTEP` performs an incremental step of garbage collection.
1882
1882
The step "size" is controlled by `data` (larger
1883
1883
values mean more steps) in a non-specified way. If
1884
1884
you want to control the step size you must
1885
1885
experimentally tune the value of `data` . The
1886
1886
function returns 1 if the step finished a
1887
1887
garbage-collection cycle.
1888
- `LUA_GCSETPAUSE` sets `data` /100 as the new value for the
1888
+ - `LUA_GCSETPAUSE` sets `data` /100 as the new value for the
1889
1889
`pause` of the collector (see | luaref-langGC | ).
1890
1890
The function returns the previous value of the
1891
1891
pause.
1892
- `LUA_GCSETSTEPMUL` sets `data` /100 as the new value for the
1892
+ - `LUA_GCSETSTEPMUL` sets `data` /100 as the new value for the
1893
1893
`step` `multiplier` of the collector (see
1894
1894
| luaref-langGC | ). The function returns the
1895
1895
previous value of the step multiplier.
@@ -2717,20 +2717,22 @@ need "inside information" from the interpreter.
2717
2717
2718
2718
lua_Debug *lua_Debug()*
2719
2719
2720
- `typedef struct lua_Debug {`
2721
- `int event;`
2722
- `const char *name; /* (n) */`
2723
- `const char *namewhat; /* (n) */`
2724
- `const char *what; /* (S) */`
2725
- `const char *source; /* (S) */`
2726
- `int currentline; /* (l) */`
2727
- `int nups; /* (u) number of upvalues */`
2728
- `int linedefined; /* (S) */`
2729
- `int lastlinedefined; /* (S) */`
2730
- `char short_src[LUA_IDSIZE]; /* (S) */`
2731
- `/* private part */`
2732
- `other fields`
2733
- `} lua_Debug;`
2720
+ >
2721
+ typedef struct lua_Debug {
2722
+ int event;
2723
+ const char *name; /* (n) */
2724
+ const char *namewhat; /* (n) */
2725
+ const char *what; /* (S) */
2726
+ const char *source; /* (S) */
2727
+ int currentline; /* (l) */
2728
+ int nups; /* (u) number of upvalues */
2729
+ int linedefined; /* (S) */
2730
+ int lastlinedefined; /* (S) */
2731
+ char short_src[LUA_IDSIZE]; /* (S) */
2732
+ /* private part */
2733
+ other fields
2734
+ } lua_Debug;
2735
+ <
2734
2736
2735
2737
A structure used to carry different pieces of information about an active
2736
2738
function. `lua_getstack` (see | lua_getstack() | ) fills only the private part
@@ -2739,28 +2741,28 @@ useful information, call `lua_getinfo` (see |lua_getinfo()|).
2739
2741
2740
2742
The fields of `lua_Debug` have the following meaning:
2741
2743
2742
- `source ` If the function was defined in a string, then `source ` is
2744
+ - `source ` If the function was defined in a string, then `source ` is
2743
2745
that string. If the function was defined in a file, then
2744
2746
`source ` starts with a `@ ` followed by the file name.
2745
- `short_src` a "printable" version of `source ` , to be used in error messages.
2746
- `linedefined` the line number where the definition of the function starts.
2747
- `lastlinedefined` the line number where the definition of the function ends.
2748
- `what` the string `" Lua" ` if the function is a Lua function,
2747
+ - `short_src` a "printable" version of `source ` , to be used in error messages.
2748
+ - `linedefined` the line number where the definition of the function starts.
2749
+ - `lastlinedefined` the line number where the definition of the function ends.
2750
+ - `what` the string `" Lua" ` if the function is a Lua function,
2749
2751
`" C" ` if it is a C function, `" main" ` if it is the main
2750
2752
part of a chunk, and `" tail" ` if it was a function that
2751
2753
did a tail call. In the latter case, Lua has no other
2752
2754
information about the function.
2753
- `currentline` the current line where the given function is executing.
2755
+ - `currentline` the current line where the given function is executing.
2754
2756
When no line information is available, `currentline` is
2755
2757
set to -1.
2756
- `name` a reasonable name for the given function. Because
2758
+ - `name` a reasonable name for the given function. Because
2757
2759
functions in Lua are first-class values, they do not have
2758
2760
a fixed name: some functions may be the value of multiple
2759
2761
global variables, while others may be stored only in a
2760
2762
table field. The `lua_getinfo` function checks how the
2761
2763
function was called to find a suitable name. If it cannot
2762
2764
find a name, then `name` is set to `NULL` .
2763
- `namewhat` explains the `name` field. The value of `namewhat` can be
2765
+ - `namewhat` explains the `name` field. The value of `namewhat` can be
2764
2766
`" global" ` , `" local" ` , `" method" ` , `" field" ` ,
2765
2767
`" upvalue" ` , or `" " ` (the empty string), according to how
2766
2768
the function was called. (Lua uses the empty string when
0 commit comments