Hi awesome FreeBSD users! I wrote a small, but almost-complete FreeBSD's sysctl(3) interface for lua (it might actually work on others *BSD system, but I didn't check).
It may help to write some awesome widget (ACPI, uptime, etc.) but I
really wanted it to be a general purpose interface, so set() is possible
and maybe in the futur, recursif get also.
It's based on sysctl(8) code, and is able to get/set any values of any
type, throwin' lua errors instead of err(3) when needed.
Here is some documentation that I didn't already wrote in the source
code, which is a little bit messy right now (lack of comments):
sysctl.get(key)
returns two values. first returned value is the sysctl(3) value,
second value is the format of returned value
- "I" int
- "UI" unsigned int
- "IK" int, in (kelv * 10) (used to get temperature)
- "L" long
- "UL" unsigned long
- "Q" quad_t
- "A" char *
- "T,dev_t" dev_t
- "S,clockinfo" struct clockinfo
- "S,loadavg" struct loadavg
- "S,timeval" struct timeval
- "S,vmtotal" struct vmtotal
sysctl.set(key, newval)
set the sysctl's key to newval. return nothin' and throw lua
error if any problem occur.
sysctl.IK2celsius(kelv)
convert a sysctl's IK value into celsius and return it.
sysctl.IK2farenheit(kelv)
convert a sysctl's IK value into farenheit and return it.
This code is new and not well tested, so don't expect it to work
perfectly. Patchs and idea are welcome :)
You can find lua_sysctl here:
http://hg.kaworu.ch
It's a mercurial repository, but you can easily fetch zip/tar.gz/tar.bz2
archives.
Have an awesome day!
Perrin Alexandre.
pgpl42F0e4oHJ.pgp
Description: PGP signature
