cjdelisle/cjdns — pull request #252 by campadrenalin (2013-07-23 05:38:49+00:00)
Title: Lua library for CJDNS administration

This is still super basic, but I'm constantly expanding it. So consider this a work-in-progress project.

Notes about compiling and installing Luasocket, since apparently that's difficult for some people...

1. I downloaded the "stable" version, which is really old, and doesn't compile with Lua5.2. Worked just fine with 5.1. The betas may be more agnostic to this, I didn't try them.
2. You *need* to edit the config file at the top level of the repo. At minimum, you need to enable (and possibly adjust) one of the LUAINC=... lines, so that the compiler can find lua.h. On my computer this line worked: `LUAINC=-I/usr/include/lua5.1` Worst case, you can run `find / -name lua.h` to locate it.
3. make && sudo make install

You also need to install bencode and json libraries. I included their project URLs in the source of cjdns.lua, close enough to the top that `head cjdns.lua` should list them all. Make sure they are all installed. On Debian stable, they should be copied to /usr/local/share/lua/5.1/. I don't know where other distros expect them, you can find out by running the Lua interpreter and importing a nonexistent module, like this: `require "bullshit"`

To try this library, run the Lua interpreter in contrib/lua and try out the following demo. Note that currently multiline comments are not yet filtered out, and will break JSON parsing.

```lua
cjdns = require "cjdns"
ai = cjdns.AdminInterface.fromConfig("/etc/cjdroute.conf")
print(ai.host)
print(ai.port)
print(ai:ping())
```

## Future features

* Strip out multiline comments before trying to parse JSON
* Separate class for config files
* Config saving
* More builtin wrappers around AdminInterface:call (only one right now is ping)
* Ability to stop and start CJDNS