Home

richardhundt edited this page Jun 27, 2012 · 31 revisions
Clone this wiki locally

logo

Welcome to the Lupa wiki!

Lupa is an object-oriented language which targets the LuaJIT2 VM. It supports a rich feature set inspired by Ruby (property access via methods), Scala (operators are methods, traits), Perl 6 (has, method, does) and Falcon.

It also has some less commonly found features, such as parsing expression grammars (via LPeg) integrated into the language (instead of the traditional PCRE), and type guards.

Here's a sample:

trait Pet[T] {
  // parameterised traits with lexical scoping
  has size : T 
}
 
class Mammal {
  has blood = "warm"
}

trait Named {
  // default property values are lazy expressions
  has name = error("A pet needs a name!")
}
 
// single inheritance with trait mixins
class Hamster from Mammal with Pet[Number], Named {

  // default initializer
  method init(name) {
    self.size = 42
    .name = name // short for self.name = name
  }   

  method greet(whom : String) {
    // string interpolation
    print("Hi ${whom}, I am ${.name}!")
  }

  // class bodies have lexical scope
  var numbers = [ "one", "two", "three", "four", "five" ]

  method count(upto) {
    // short functions
    upto.times((_) => { print(numbers[_]) })

    // same thing, but `times' as infix operator
    upto times => print(numbers[_])
  }
}

var rudy = Hamster.new("Rudy")
rudy.greet("Jack")
rudy.count(5)

Next check out: