lua-users home
lua-l archive

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

My Linux syscall library is reasonably ready for use, if anyone is interested (though still alpha!). Not sure if it is of any use to anyone except me...

Note this library currently *only* works with LuaJIT 2.0 (recent version), as it uses FFI bindings, and only with Linux.

This implements in a (relatively) easy to use way over 100 Linux system calls, that is the calls in man 2, and some helper functions, all with a nice Lua interface, currently most of the main ones, plus support for unix, ipv4, ipv6 and (in progress) netlink sockets:

open, close, creat, chdir, mkdir, rmdir, unlink, acct, chmod, link, umask, uname, gethostname, sethostname, getuid, geteuid, getpid, getppid, getgid, getegid, fork, execve, wait, waitpid, _exit, signal, gettimeofday, settimeofday, time, clock_getres, clock_gettime, clock_settime, sysinfo, read, write, pread, pwrite, lseek, send, sendto, sendmsg, recv, recvfrom, recvmsg, readv, writev, getsockopt, setsockopt, select, epoll_create, epoll_ctl, epoll_wait, sendfile, dup, fchdir, fsync, fdatasync, fcntl, fchmod, socket, socketpair, bind, listen, connect, accept, getsockname, getpeername, mmap, munmap, msync, mlock, munlock, mlockall, munlockall, mremap, madvise, pipe, access, getcwd, nanosleep, syscall, stat, fstat, lstat, ioctl, eventfd, truncate, ftruncate, pause, reboot, sync, shutdown, ksyslogctl, mount, umount,
nice, getpriority, setpriority, prctl, alarm, waitid, inotify_init, inotify_add_watch, inotify_rm_watch

I do intend at some point to make a version that works with standard Lua, probably by writing a script to generate the bindings. 

I may make fixes to make it work with other Unix versions, but it is not a priority.

The best documentation at the moment is the test cases, which cover almost all functions. You can use text versions of the constants, which makes things fairly readable (at least compared to C!):

mem = assert(S.mmap(nil, size, "read", "private, anonymous", -1, 0))
sv, err = S.socketpair("unix", "stream")
S.mount("none", tmpfile, "tmpfs", "rdonly, noatime")

File descriptors are garbage collected, and have methods, so you can do fd:read(...), fd:close()  etc.