Button

Overview

More complete docs will be at Orbit's LF page shortly.

If you are itching to try it add this repository to your LuaRocks config and then do luarocks install orbit. You can find samples in Orbit's directory inside your local LuaRocks repository. Some samples need LuaSQL, do luarocks install luasql-sqlite3 to be able to run them.

Orbit is an MVC web framework for Lua. The design is inspired by lightweight frameworks such as Camping and web.py. It completely abandons the current CGILua model of "scripts" in favor of applications. Each Orbit application can fit in a single file, but you can split it into multiple files if you want. All Orbit applications follow the WSAPI protocol, so currently work with Xavante, CGI and Fastcgi. It includes a launcher that makes it easy to launch a Xavante instance for development, and are easily launched from CGI and Fastcgi-enabled webservers using the generic WSAPI launchers.

Simple app

Below is a very simple Orbit application:

#!/usr/bin/env wsapi

local orbit = require"orbit"
local cosmo = require"template.cosmo"

local songs = orbit.new()

function songs.index(web)
   local songlist = {
      "Sgt. Pepper's Lonely Hearts Club Band",
      "With a Little Help from My Friends",
      "Lucy in the Sky with Diamonds",
      "Getting Better",
      "Fixing a Hole",
      "She's Leaving Home",
      "Being for the Benefit of Mr. Kite!",
      "Within You Without You",
      "When I'm Sixty-Four",
      "Lovely Rita",
      "Good Morning Good Morning",
      "Sgt. Pepper's Lonely Hearts Club Band (Reprise)",
      "A Day in the Life"
   }
   return songs.layout(songs.render_index({ songs = songlist }))
end

songs:dispatch_get(songs.index, "/")

function songs.layout(inner_html)
  return html{
    head{ title"Song List" },
    body{ inner_html }
  }
end

orbit.htmlify(songs, "layout")

songs.render_index = cosmo.compile([[
     <h1>Songs</h1>
        <table>
        $songs[=[<tr><td>$it</td></tr>]=]
        </table>  
]])

return songs.run

The example uses Orbit's built-in html generation (orbit.htmlify), but you are free to use any method of generating HTML that you want, such as the Cosmo template library, for instance.

Run this either with the orbit dev. server (orbit songs.lua) or through CGI or FastCGI.

OR Mapping

Orbit also includes a basic OR mapper that currently works with LuaSQL's SQLite3 and MySQL drivers (with the HEAD of LuaSQL!). The mapper provides dynamic search methods, a la Rails' ActiveRecord (find_by_field1_and_field2{val1, val2}), as well as templates for conditions (find_by("field1 = ? or field1 = ?", { val1, val2 })). The sample applications use this mapper.

A nice side-effect of the Orbit application model is that we get an "application console" for free. For example, with the blog example we can add a new post like this:

$ lua51 -i blog.lua
> p = blog.posts:new()
> p.title = "New Post"
> p.body = "This is a new blog post. Include *Markdown* markup freely."
> p.published_at = os.time()
> p:save()

You can also update or delete any of the model items right from your console, just fetch them from the database, change what you want and call save() (or delete() if you want to remove it).

Docs and download

There's not much documentation right now, apart from the source code and sample applications.

See the start of this page on instructions for installing via LuaRocks (the preferred method). Even if you do not have LuaRocks the rockspec file tells what dependencies you need to fetch.

Orbit powered sites

  • Lablua - Using the CMS sample app, Apache 2 as front-end, proxying to a Xavante server, all running on a Linksys NSLU2