Lua shenanigans

Lua shenanigans

After some time away from building stuff with Lua in my spare time I wanted to revisit it and thus decided to start another project with OpenResty and Lapis.

Turns out there’s a reason for it being relatively niche. Lapis works fine, just like a while back. I reported some minor issues, but they were promptly fixed or explained and I’m still a happy user trying to recommend everyone to at least give it a try ;)

So, I was going to use PostgreSQL and Lapis now even uses a better api than ngx_postgres (which is a cool hack, but I wasn’t entirely sold…) in the form of pgmoon - and it works fine.

My other dependency would be a Markdown library. I had used lunamark last year but forgotten about my problems. To cut the long story short, I found my own bug reports and applied my fixes again. boo.

I don’t know how I found out about lunamark, but according to the lua toolbox it’s endorsed by 2 people.

Anyway, this is how you lua: (it’s part howto, part rant, part exercise in futility)

  • download latest openresty
    • tar xaf … ; cd …
    • ./configure --prefix=/usr/local/openresty- \ --with-luajit --with-pcre-jit
    • wonder why it doesn’t work because of missing ldconfig
    • prefix PATH=$PATH:/sbin and retry configure
    • make && make install
    • wonder why it doesn’t work because libluajit can’t be found
    • retry configure as root, make && make install
    • it works?
  • git clone; cd luarocks; git checkout v2.0.13
    • ./configure --prefix=/usr/local/openresty/luajit \ --with-lua=/usr/local/openresty/luajit/ \ --lua-suffix=jit-2.1.0-alpha \ --with-lua-include=/usr/local/openresty/luajit/include/luajit-2.1
    • make && make install
  • alias luarocks=/path/to/luarocks
  • luarocks install lapis - hey, this works. surprise
  • luarocks install lunamark
    • this fails, so back to source
    • git clone && cd lunamark && luarocks make lunamark-0.3-2.rockspec
    • notice the still unfixed lpeg problem
      • luarocks remove --force lpeg && luarocks install lpeg-0.10.2-1
  • notice the unicode problem with slnunicode
    • notice there hasn’t been a release since your own fix, so manually build head
    • git clone slnunicode-1.1a
    • now move this directory to from where you installed openresty. sounds complicated, but for me it was:
      • cd /opt/src/ngx_openresty- && ln -s /opt/src/slnunicode-1.1a
      • make -f slnunicode-1.1a/Makefile
      • ignore the error because the test can’t run because your lua binary is somewhere else
      • cp /usr/local/openresty-
      • restart openresty

My project is called wheee and it’s a small wiki engine. It includes users, pages and revisions. That’s about it.

TL;DR: I love Lua and Lapis is a pretty cool framework if you’re just getting started or not want to care about low level stuff for a fun side project. BUT if you’re comparing it to the frictionless experience of Rails or something, you’ll probably be annoyed.

Oh, and I’m gonna try out this markdown library now, it’s endorsed by 5 people.