Saturnus - A rust-inspired dynamic typed programming language

Started by sigma-octantis, Jul 21, 2023, 07:37 AM

Previous topic - Next topic

sigma-octantis

Saturnus



The main Saturnus repository can be found on github: https://github.com/sigmasoldi3r/Saturnus

Saturnus is a programming language that aims to have a simplified mix of Rust programming language and Lua.

The original purpose of this language was to provide an easy-to-learn syntax, and fast compilation times, to replace Lua scripts currently.

Beware that the compiler is under alpha stage, that means that the pure core-most features are working, but there are some bugs/missing features, like trailing commas throwing a compilation error, missing range generation/linear for... They're pointed out in the repo's readme.

Contributions are welcome!! If you find a bug/missing feature, open an issue.

Key points of the language that might be a little bit disruptive, if you come from lua:
  • All statements must end with a semicolon (eg: let i = 0;)
  • Concatenation operator is ++ (eg "a" ++ "b")
  • Method dispatching uses dot when lua uses :, and static dispatch uses :: when lua uses a dot

How does it look?

You can find some examples at the folder /examples of the repo!

But, here you have some brief examples:

// Here is how decorators work in Saturnus:
fn MakeArcane() {
  // You return a function,
  // and that will decorate the target class.
  return (target) => {
    target.prototype.kind = "ARCANE";
  };
}

// One of the advantages of Saturnus over Lua,
// is that you can have decorator code generation:
@MakeArcane()
class Mundane {
  let kind = "mundane";

  fn what_kind_is(self) {
    return self.kind;
  }
}

let mundane = Mundane {/* Use default constructor fields */};

// If you run the output you'll be surely suprised:
print("My mundane thing is in fact: " ++ mundane.what_kind_is());

Don't like the classness of the language? You can revert back to only-functions programming also!

Remember: Saturnus does not care if you embed everything into classes or not, you can also create programs like in the old Lua fashion:

let i = 0;
fn plus_one() {
  i += 1;
}
fn how_many() {
  return i;
}
fn sum_and_tell() {
  plus_one();
  return how_many();
}
print("Summing one: " ++ sum_and_tell());
print("Summing one: " ++ sum_and_tell());
print("Summing one: " ++ sum_and_tell());

// Also your typical table literals:
let player = {
  health: 100,
  hurt: (self, amount) => {
    self.health -= amount ?? 1;
  }
};
print("Player's health: " ++ player.health);
print("Hurt 10");
player.hurt();
print("Now: " ++ player.health);

Tell me if you want more examples! (I'm working on a repository with many more scripts that are currently running on my server)
Check out Saturnus - a language that compiles to lua
You'll be surprised how modern languages can simplify development!

Also check out my ComputerCraft scripts repository!

sigma-octantis

Also, I've pushed some artifacts, in case you don't want to compile by yourself. You can find them at the workflow resulting artifacts.
Check out Saturnus - a language that compiles to lua
You'll be surprised how modern languages can simplify development!

Also check out my ComputerCraft scripts repository!