[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: c function returning table
- From: erik@... (Erik Hougaard)
- Date: Thu, 22 Jun 2000 16:35:55 +0200
// Get Files and return a table with all files names
void GetFiles(lua_State *lua_state)
{
WIN32_FIND_DATA FindData;
HANDLE FindHandle;
lua_Object tempTable;
int i = 1;
tempTable = lua_createtable(lua_state);
FindHandle = FindFirstFile(luaL_check_string(lua_state,1),&FindData);
if (FindHandle != INVALID_HANDLE_VALUE)
do
{
if (FindData.dwFileAttributes & (FILE_ATTRIBUTE_DIRECTORY |
FILE_ATTRIBUTE_SYSTEM |
FILE_ATTRIBUTE_HIDDEN) )
{
// What do we do with directories etc..
}
else
{
// Add filename to table
lua_pushobject(lua_state,tempTable);
lua_pushnumber(lua_state,i);
i++;
lua_pushstring(lua_state,FindData.cFileName);
lua_settable(lua_state);
}
} while(FindNextFile(FindHandle,&FindData));
FindClose(FindHandle);
lua_pushobject(lua_state,tempTable);
}
Here is a small example of a function that will do what you need (Win32)
/Erik
----- Original Message -----
From: "John Passaniti" <jmp@pt.com>
To: "Multiple recipients of list" <lua-l@tecgraf.puc-rio.br>
Sent: Thursday, June 22, 2000 4:26 PM
Subject: c function returning table
>
> Can someone point me to an example of a C function that returns a table?
I
> have the need to read a directory and place the filenames in a table.
> While I could decompose this with wrappers for opendir(), readdir(), and
> closedir(), I would rather just return everything in a single table in one
> shot.
>
>