Gotcha! Ok, try this:[pascal]function lua_Search(L : PLua_State) : integer; cdecl;
var
i, n, idx : integer;
searchResult : TSearchRec;
path, mask: AnsiString; // You should always use AnsiStrings and not Strings
begin
n := lua_gettop(L); // Get the number of items being passed in
if n > 0 then
begin
path := luatostring(L, 1);
if n > 1 then
mask := luatostring(L, 2)
else
mask := '*.*';
end
else
begin
mask := '*.*';
path := ExtractFilePath(ParamStr(0));
end;
lua_newtable(L); // Create a new table
idx := lua_tointeger(L, 1);
lua_Search := 1;
i := 1;
if FindFirst(path + mask, faAnyFile, searchResult) = 0 then
begin
repeat
lua_pushinteger(L, i);
inc(i);
luapushstring(path + mask);
lua_settable(L, idx);
until FindNext(searchResult) <> 0;
FindClose(searchResult);
end;
end;[/pascal]

Later (if your using my TLua object) register the function with:[pascal]Lua.RegisterMethod('FindFiles', @lua_Search)[/pascal]
If you are using pure Lua, then registering the function becomes:[pascal]luapushstring(L, 'FindFiles');
lua_pushcfunction(L, @lua_Search);
lua_settable(L, LUA_GLOBALSINDEX);[/pascal]

Then for a lua script:
Code:
results = FindFiles&#40;SomePath, '*.bmp'&#41;
if results~= nil then
  for k, v in pairs&#40;results&#41; do
    print&#40;v&#41;
  end
end
On a side note; really you should allow for a recursive flag, allow path and filename to be passed in a new table instead of all in one, and other options. By default, FindFirst/FindNext are not recursive, and you would have to write handlers to manage this. Unfortunately (for you) I never completed the code I was working on for a good cross platform lua_FindFiles implementation, if I do, I'll post it up