Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Rol: a language transpiled to Lua for all you Lua syntax haters
- // Overall the language is quite C-like
- print("Hello, World!")
- // Semicolons are not required, but can be used
- print("Semi");print("colon")
- // Idk about variable syntax, most likely similar to Kotlin:
- var a: Int = 1
- // Rol has type inference
- var a = 1
- // There is also a dynamic type
- var a: dyn = 1
- // Blocks are delimited by braces
- if (a == 1) {
- print("a is 1")
- } else {
- print("a is not 1")
- }
- // We've got both C and Python style loops
- for (var i = 1; i < 5; i++) {
- print(i)
- }
- for (i: Int in Range(5)) {
- print(i)
- }
- // Functions are fun
- fun hello(times: Int): String {
- return "Hello" * times
- }
- // 'extern' prevents name mangling for Lua interop
- // All parameters are dyn by default in extern functions
- extern print(obj)
- // OOP support is not much, just structs
- struct Complex {
- var re: Int
- var im: Int
- // Constructors are supported
- init(this: Complex, re: Int) {
- this.re = re
- this.im = 0
- }
- }
- var c = new Complex(1, 0)
- var r = new Complex(1)
- // Instance methods are just sugar
- // It also allows adding methods on unowned structs
- instance fun add(this: Complex, other: Complex): Complex {
- return new Complex(this.re + other.re, this.im + other.im)
- }
- var res = c.add(r)
Advertisement
Add Comment
Please, Sign In to add comment