Weekends Projects: lua as config-language 16

Posted by jan Sat, 09 Feb 2008 23:09:00 GMT

With the first implementation of mod_cml and later mod_magnet smart users asked why we don’t use lua also as config language for lighttpd.

Up to now I was pushing back and saying that a huge change in the configfile would make upgraders very unhappy as they would have to rewrite the config files. Looking at what we have for 1.5.0 right now, we need tweaks anyway.

This always happens if you rip a thing apart: you see more things that should be cleaned up. My first experiments are a bit done:

server = {
        name = "my.example.org",
        modules = {
                "mod_indexfile" 
        },
        ["errorfile-prefix"] = "foobar",
}

sockets = {
        [":80"] = {
                server = { name = "foo.example.org" },
                HTTP = { url = function(url)
                        if url == "foo" then
                                server.name = "baz.example.org" 
                        end
                end },
        }
}

sockets[":80"].HTTP.url("foo")
print(server.name)

This is a first idea. It shows how the LUA syntax isn’t sooo different from our current config syntax.

  • The global variables, stay global as now.
  • socket conditionals is now a simple array of sockets
  • conditionals are functions, now you can do what you want with it

I hope that I can handle the full config syntax into this structure. For now it is looks more appealing that ripping the old config-parser code apart and turn it into glib-notation. With all the conditionals and types we basicly have implemented our own scripting language.

Let’s see where this leads too.

Trackbacks

Use the following link to trackback from your own site:
http://blog.lighttpd.net/articles/trackback/4862

Comments

Leave a response

  1. Tim Sun, 10 Feb 2008 07:13:56 GMT
    Sounds interesting. Though I must admit, I'm simply more interested in a bug free release right now from Lighttp than anything else.
  2. Viktor Sun, 10 Feb 2008 08:07:38 GMT
    There are quite a number of levels which could be condensed. I would be prone to more error if i type in a much longer code. I keep mine brief.
  3. fcicq Sun, 10 Feb 2008 10:31:03 GMT
    seems good, we need a lighttpd.conf converter :D -- just kidding
  4. anonymouse Sun, 10 Feb 2008 14:24:08 GMT
    fcicq jokes but I bet it would not be so difficult to create a perl (or ruby) to at least partly convert the configs to newspeak.
  5. Fernando Silva Sun, 10 Feb 2008 14:28:37 GMT
    Using mod_magnet we (me and a collegue) created a LUA scripting file that implements a virtual hosting mechanism using a LUA file as the database. Advantages: 1. no need to change the current lighttpd configuration that needs to restart the server 2. no need to use mysql with the obvious performance (and caching problems) 3. much more powerfull than simple vhost, because it allows to do things like automatic 302 redirection 4. so easy to update file to add, remove or change a virtual host If lighttpd continues to use more LUA, we will be able to implement a good set of modules as LUA extensions, without hitting the server performance.
  6. Jan (the other one) Mon, 11 Feb 2008 15:46:40 GMT
    i like those square brackets. lua looks like a mutant of python and php :) perhaps you can invent a meta conf scheme in XML and a converter for every conf language. then there is no problem in switching the conf as often as you like :)
  7. Keagon Mon, 11 Feb 2008 15:47:15 GMT
    I would like to see a quick release of 1.5 ... of course, with bugs ironed out and all.
  8. Peter Mon, 11 Feb 2008 17:58:04 GMT
    Sounds interesting indeed and the comparison of mutant of python and php was the choke of the day ;-)
  9. Alex Kloss Tue, 12 Feb 2008 08:25:59 GMT
    That means one could use lua string.match regexp, which on the upside is faster than libpcre yet on the downside will make config file conversion rather difficult on more complex regexp.
  10. Bertrand Mansion Fri, 15 Feb 2008 15:34:33 GMT
    I love it :) The more you add lua, the more I like lighty.
  11. moo Sat, 16 Feb 2008 16:24:18 GMT
    yeah, it's flexible, but how about the performance? on each request lua gotta go though server = .. things? and btw, there's some question left not thought yet. like should it be url.rewrite (...) which is a function call or url.rewrite = (...) which is just a variable. should it be url.rewrite = ("abc" = "abc" .. var.runtimevariable, "def" = "def" .. var.runtimevariable2 ..............) which is slower because all variable has to be eval at runtime or url.rewrite = ("abc" = "abc%0", "def" = "def%1") which is faster because only one of %0/%1 is only eval if the single rule is matched
  12. ka2 Tue, 19 Feb 2008 02:51:29 GMT
    ubuntu gutsy's lua is too old for lighttpd 1.5 though :( Lighttpd says it needs 5.1, gutsy has 5.0
  13. Laph Tue, 19 Feb 2008 13:27:49 GMT
    Please, no more unusual external dependencies! No LUA-RegExp as long as they differ from PCRE! Current conf-syntax is powerful, easy to learn and work with, if you know PCRE at least a bit - and hey, every Web-Programmer knows PCRE regardless of her/his background (Perl, PHP, Java, MySQL...).
  14. 1.5 Wed, 20 Feb 2008 21:37:57 GMT
    I uh, thought 1.5 was at the stage where it was about getting rid of regressions, not performing total rewrites. I was almost in a situation where I'd want to use lighty, then I saw this... no thanks. If there is no control whatsoever over the release process (and this seems to demonstrate that), then it's not going to be a fun ride on board.
  15. lu_zero Mon, 25 Feb 2008 08:52:05 GMT
    Probably would be better benchmark this before choosing such radical change.
  16. Anders Thu, 28 Feb 2008 15:14:08 GMT
    Yeah, Lua is really nice to use as a configuration parser: it also gives a lot more power to the person who is setting everything up :)
Comments