lua-users home
lua-l archive

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


Hmm...
I already thought that could be the problem, but to be sure I changed the for loop to start at 1 and end at subdir_count and this gave the following:

c:\test\lua\a
c:\test\lua\a\ab
table

Unhandled Exception: System.Exception: enum.lua:40: attempt to index a nil value

(called with listFiles("c:\\test\\lua\\a") )

so it seems to skip the first entry.
For your information, the line

local subdirs = luanet.System.IO.DirectoryInfo(name):GetDirectories()

returns an array of DirectoryInfo objects (at least in .Net). Looks like multiple levels of recursion is messing things up here. I'm not an expert in Lua but can the combination of local variables and arrays cause any trouble ? Or is this specific to LuaInterface and has nothing to do with Lua itself ?

Regards,
Frank

From: Brian Weed <bw@imaginengine.com>
Reply-To: Lua list <lua@bazar2.conectiva.com.br>
To: Lua list <lua@bazar2.conectiva.com.br>
Subject: Re: LuaInterface, Recursion and arrays
Date: Tue, 30 Aug 2005 10:30:35 -0400

Tables are normally one based, not zero based. Dunno if that is your problem...

Brian

Frank Black wrote:

Hi There,

I have the following function that should list all directory names under a specified root:

local listFiles
listFiles = function(name)
    Console.Error:WriteLine(name)
    local subdirs = luanet.System.IO.DirectoryInfo(name):GetDirectories()
    local subdir_count = subdirs:get_Length()
    local i
    for i = 0, subdir_count-1 do
        listFiles(subdirs[i].FullName)
    end
end

listFiles("c:\\test\\lua\\a")

My test directories are organized as follows:

c:\test\lua
c:\test\lua\a
c:\test\lua\a\aa
c:\test\lua\a\ab
c:\test\lua\b

when calling the function with "c:\test\lua\a" the following (correct) results are obtained:
c:\test\lua\a
c:\test\lua\a\aa
c:\test\lua\a\ab

but calling listFiles("c:\test\lua") causes a stack overflow exception. and only prints
c:\test\lua\a
over and over again...

I'm totally stuck, but probably some simple thing I'm missing. It looks like the subdirs variable is not correctly assigned a new array value..
Any ideas ?
Thanks in advance
Frank

_________________________________________________________________
Express yourself instantly with MSN Messenger! Download today it's FREE! http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/




_________________________________________________________________
FREE pop-up blocking with the new MSN Toolbar - get it now! http://toolbar.msn.click-url.com/go/onm00200415ave/direct/01/