code_gs

Untitled

Jun 5th, 2020
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.29 KB | None | 0 0
  1. # This is a comment
  2. #[ This is a block comment ]#
  3. #[[ Double block comment #[ ]# This is still a comment since it hasn't been double closed yet ]]#
  4. #[[[ And so on ]]]#
  5.  
  6. # Everything is pass-by-reference
  7.  
  8. # library == namespace in C++
  9. library foo
  10. {
  11. # Foo has one template argument
  12. # Class == typename in C++
  13. class Foo(Class data)
  14. {
  15. # Default class scope is public
  16.  
  17. # Class aliasing
  18. Class Data = data
  19.  
  20. # ctor is the constructor keyword
  21. ctor()
  22. {}
  23.  
  24. ctor(Data i)
  25. {
  26. self.i = i # We can use self. to target the i we want
  27. i2 = i + 1 # The self. scope is automatically searched, so it's optional here
  28. }
  29.  
  30. # dtor is the destructor keyword
  31. dtor()
  32. {}
  33.  
  34. Data GetI()
  35. {
  36. return i
  37. }
  38.  
  39. protected:
  40. Data i
  41.  
  42. private:
  43. Data i2
  44. }
  45.  
  46. # assert == static_assert and _assert in C++, but it runs as part of normal execution
  47. # so it can appear straight out in the file or as part of a regular function that checks something at runtime
  48. assert(true == !false)
  49.  
  50. # type == decltype
  51. # Types can be compared outright with ==, none of this std::is_same bullshit
  52. # The type of all classes is Class. The type of Class is Class
  53. assert(type(Class) == Class)
  54. assert(type(Number) == Class)
  55.  
  56. # ctor and dtor are also keywords that return the ctor and dtor of a class
  57. assert(dtor(Foo) == Function)
  58.  
  59. try
  60. {
  61. assert(false, "We ran into some error here")
  62. }
  63. catch(AssertException e)
  64. {
  65. print(e.Error)
  66. continue
  67. }
  68. catch(Exception e)
  69. {
  70. print("This will not be ran because we called continue above. If we didn't, this would be run after the first catch since AssertException is also an Exception.")
  71. }
  72. finally
  73. {
  74. print("We errored. This will still run. If we had called break instead of continue, this would have not been run.")
  75. }
  76.  
  77. try
  78. {
  79. assert(false, CustomExceptionClass("We can throw an exception instead of a string"))
  80. }
  81.  
  82. # & == logical and, | == logical or
  83.  
  84. # Local Number variable. Default scope is global
  85. local Number i = 5
  86.  
  87. # Double and comparison, i != (3, 4) -> i != 3 & i != 4
  88. if (i != (3, 4))
  89. {}
  90.  
  91. # Double or comparison, i != <4, 5> -> i != 4 | i != 5
  92. if (i == <4, 5>)
  93. {}
  94. }
  95.  
  96. foo.Foo(Number) f(5)
  97. assert(f.GetI() == 5)
Add Comment
Please, Sign In to add comment