lua-users home
lua-l archive

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


I have added Linux support for getdents to my FFI system call library https://github.com/justincormack/ljsyscall 

It seemed easier to use the system call directly rather than use readdir.  The call returns a table of the files in the directory, it calls getdents until it returns zero. There is a convenience function that opens a named file and returns the directory entries so you can write:

local d = assert(S.dirfile("/dev"))
assert(d.zero, "expect to find /dev/zero")
assert(d["."], "expect to find .")
assert(d[".."], "expect to find ..")

Feel free to rip out the (small) amount of relevent code if you only want this function...

I am intending to add OS X support at some point to this library, but it is going to be a fair amount of work. It is tested on 32 and 64 bit x86 and arm.

Justin


2011/6/6 Dimiter "malkia" Stanev <malkia@gmail.com>
I've just wrote something last thursday. But I gave up, when I came to OSX and Linux.

The problem for me was "struct dirent" - it's defined very differently on various "unix" like platforms, and can't be exposed safely. Well one can do it, if he is very.

For Windows that was easier - for 64-bit might be just a bit trickier, and if UNICODE support is needed might complicate it a bit (but can it be done easy through lua).

I also want to use only FFI, and nothing else (it's for a different reason, I just don't want to deal with one more and one more compilation - having luajit binary/dll for each platform, and then having pulled certain other "C" library that I can use - whether I recompiled or someone else - it won't matter).


On 6/6/2011 6:42 AM, Attila wrote:
Dear All,

Can somebody help me with LuaJIT FFI? I don't really understand it's
mechanism, I used alien to iterate through a directory's files (I don't
like os.execute with DIR/LS command, because it flashes the shell, and
that's an ugly solution I think). This code worked well:
http://pastebin.com/tJ0iFkyS
If that possible to rewrite it with LuaJIT, but without any additional
dll? I don't know C/C++, I am mainly Lua programmer, so please help :)

Regards,
Attila