Skip to content

Instantly share code, notes, and snippets.

@Seggan
Created October 6, 2022 19:15
Show Gist options
  • Save Seggan/48620562010ca82f37cfa38904125d68 to your computer and use it in GitHub Desktop.
Save Seggan/48620562010ca82f37cfa38904125d68 to your computer and use it in GitHub Desktop.
Rol Showoff
// 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, is 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
// 'is' gives it an alias (becuase often the code that uses this is named the same)
extern print(obj) is luaPrint
// 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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment