lua-users home
lua-l archive

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


Hello, 

some beginner's questions...
1. about lua.c
I got a problem with the last version of lua.c with the for loop:

Lua 4.1 (beta)  Copyright (C) 1994-2001 TeCGraf, PUC-Rio
> a = {"what", "ever"}
> for i = 1, getn(a) do
>> print(a[i])
error: `do' expected;
  last token read: `doprint' at line 1 in stdin

(the same with for k, v in a do...)

I had to insert a space before print to make it work correctly. Is it the
expected behaviour?

2. Can't recursive functions be defined as local like in:
fac = function (n)
         local fc = function(n)
                       if n < 2 then
                          return 1
                 else
                    return n * fc(n-1)
                 end
              end
         return fc(n) 
      end
--> error: attempt to call global `fc' (a nil value)
But if fc() is not local, everything works perfectly.
Coul you give some explanations about the reasons it's like that (or could you
tell where to find some explanation ?)

3. last thing
I've found a nice place for beginners, called PLEAC
(http://pleac.sourceforge.net/). It sure would be nice if lua had an entry there
too!!

best regards
Stephane