Guest User

Untitled

a guest
Sep 19th, 2022
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. // Rol: a language transpiled to Lua for all you Lua syntax haters
  2. // Overall the language is quite C-like
  3. print("Hello, World!")
  4.  
  5. // Semicolons are not required, but can be used
  6. print("Semi");print("colon")
  7.  
  8. // Idk about variable syntax, most likely similar to Kotlin:
  9. var a: Int = 1
  10.  
  11. // Rol has type inference
  12. var a = 1
  13.  
  14. // There is also a dynamic type
  15. var a: dyn = 1
  16.  
  17. // Blocks are delimited by braces
  18. if (a == 1) {
  19. print("a is 1")
  20. } else {
  21. print("a is not 1")
  22. }
  23.  
  24. // We've got both C and Python style loops
  25. for (var i = 1; i < 5; i++) {
  26. print(i)
  27. }
  28.  
  29. for (i: Int in Range(5)) {
  30. print(i)
  31. }
  32.  
  33. // Functions are fun
  34. fun hello(times: Int): String {
  35. return "Hello" * times
  36. }
  37.  
  38. // 'extern' prevents name mangling for Lua interop
  39. // All parameters are dyn by default in extern functions
  40. extern print(obj)
  41.  
  42. // OOP support is not much, just structs
  43. struct Complex {
  44. var re: Int
  45. var im: Int
  46.  
  47. // Constructors are supported
  48. init(this: Complex, re: Int) {
  49. this.re = re
  50. this.im = 0
  51. }
  52. }
  53.  
  54. var c = new Complex(1, 0)
  55. var r = new Complex(1)
  56.  
  57. // Instance methods are just sugar
  58. // It also allows adding methods on unowned structs
  59. instance fun add(this: Complex, other: Complex): Complex {
  60. return new Complex(this.re + other.re, this.im + other.im)
  61. }
  62.  
  63. var res = c.add(r)
Advertisement
Add Comment
Please, Sign In to add comment