ChaiScript has an object system built in, for types defined within the ChaiScript system.
attr Rectangle::height
attr Rectangle::width
def Rectangle::Rectangle() { this.height = 10; this.width = 20 }
def Rectangle::area() { this.height * this.width }
rect.height = 30
print(rect.area())
Since ChaiScript 5.4.0 it has been possible to use the "class" keyword to simplify this code.
class Rectangle {
attr height
attr width
def Rectangle() { this.height = 10; this.width = 20 }
def area() { this.height * this.width }
}
rect.height = 30
print(rect.area())
- See also
- attr
-
def