Take a tour !
A quick overview of Luart
Hello World revisited
The "Hello World !" is a classic, but let's evolve the concept to a more personalized way. For that, we will use a basic Object oriented programming. Standard Lua allows for OOP programming but it requires users to learn elaborate concepts related to metamethods, or to use a third party library.
Luart provides simple OOP, out of the box, through the use of the Object
global function :

You just have declared your first empty object ! As you can see, it has a type of Object
, which Luart uses to create instanced values. This object can be used to create a new value even if it is empty :

Now the variable sam
contains an instance value of the Greet
object. Let's add some capabilities to the Greet object :

We just have defined a Greet:hello()
method for the Greet
object. But as you can see, it throws an error when calling it from the sam
instance. You guessed it, that's because the self.name
field is not defined.
To add a new field name
, let's define a constructor
method to do all the necessary :

We can now use the Greet
object and its constructor
method (called upon instantiation) to greet anyone else. No metatables, no metamethods, rather easy !