lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

I believe there are two little problems with the HTML version of the Lua 4.0 
documentation. I was quite confused by these, until I had the idea of 
cross-checking with the PDF doc.:

4.1 - Lexical Conventions
Missing the '%' character to the list of other tokens.

I am not sure for the absence of `^' (both in HTML and PDF), as it seems to 
belong to the math. lib., but is listed in the binop below.
Same for `:', which is used in the notation t:f(x). Should it be in the list 
above, or is it a special notation, not a token (whatever a token really 
is...)? Since you list this notation as "syntaxic sugar", perhaps it is not a 
real token (ie. doesn't generate a specific bytecode, or something like that).

The Complete Syntax of Lua
binop ::= [snip] | `<B>\^{ </B>' | [snip] | `<B>\&nbsp;{ </B>'=} <BR> [snip]

In the PDF file, we have `^' for the first item (displayed as `\^{ ') and `~=' 
for the second one (displayed as `\ { '=}).
I suppose it is a little bug in a HTML generation program.

On a lighter side, I have found this amusing site:
It is akin to the Hello world site, ie. it is meant to show the implementation 
of a simple task in the maximum number of languages. It is a bit more 
sophisticated than the Hello world, though, because it features loop and 
string formatting.

Of course, I checked to see if Lua was showcased. Not! So I choose to make my 
first Lua program with this exercice. Here is my work:

function PrintBottleNumber(n)
	local bs
	if n == 0 then
		bs = "No more bottles"
	elseif n == 1 then
		bs = "One bottle"
		bs = n .. " bottles"
	return bs .. " of beer"

for bn = 99, 1, -1 do
	write(PrintBottleNumber(bn), " on the wall, \n")
	write(PrintBottleNumber(bn), "\n")
	write("Take one down and pass it around,\n")
	write(PrintBottleNumber(bn-1), " on the wall, \n\n")
write("No more bottles of beer on the wall,\nNo more bottles of beer\n")
write("Go to the store, buy some more!\n")

It is probably not very Lua-like, ie. I made it more in the spirit of VBScript 
than using advanced Lua features (beside the Lua 4.0 `for'). If you have some 
ideas to improve it...
Otherwise, I will try and send this submission.


Philippe Lhoste (Paris -- France)
Professional programmer and amateur artist