Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/cargo/janus/rustix-0.37.25
Browse files Browse the repository at this point in the history
  • Loading branch information
sigmasoldi3r authored Nov 4, 2023
2 parents acd908e + 2fa3400 commit 42311a1
Show file tree
Hide file tree
Showing 20 changed files with 1,131 additions and 760 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/target/
/src/assets/*.lua
47 changes: 47 additions & 0 deletions examples/basic.saturn
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Basic examples

// This is a comment
/*
this also is.
*/

// Declare variables
let some_var = "foo";
let some_char = 'a'; // This is a number actually.
some_char += 1;
print(some_var, some_char);

// Mutate them
some_var = 5;
some_var += 1;
print(some_var);

// Declare functions
fn the_foo() {
return "bar";
}

// Use them
let answer = the_foo();
print(answer);

// Conditions
if true {
print("Of course");
} else {
print("Never");
}

// Do-block
{
let this_is = "isolated from the rest";
print("of_the_code");
}

// Can be used as an expression too!
let my_var = "Foo";
let result = {
let my_var = "another one";
return my_var ++ ".";
};
print(result, my_var);
9 changes: 9 additions & 0 deletions examples/collections.saturn
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
require("../src/assets/std");

let x = [1, 2, 3];
let y = [4, 5, 6];
let z = x ::: y;

for (k, v) in entries(z) {
print(k ++ " => " ++ v);
}
15 changes: 12 additions & 3 deletions examples/extra_op.saturn
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
// Example usage of extra operators:
let { operator, entries } = require("../src/assets/std");

fn __pipe_right(left, right) {
@operator("|>")
fn pipe_right(left, right) {
return right(left);
}

@operator("<|")
fn pipe_left(left, right) {
return left(right);
}

// Example usage of extra operators:
let r = 101
|> (a => a + 10)
|> (a => a * 2)
|> tostring;

print("Result = " ++ r ++ " (" ++ type(r) ++ ")");
let kind = type <| r |> a => "(" ++ a ++ ")";

print("Result = " ++ r ++ " " ++ kind);
13 changes: 11 additions & 2 deletions examples/function_decorators.saturn
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@


fn Test() {
fn test() {
return (target, name) => {
print("Adding " ++ name ++ " to the test suite!");
};
}

@Test()
@test()
fn my_func() {
print("Some func");
}

fn foo() {
return (_, n) => print("Adding foo to", n);
}
fn bar() {
return (_, n) => print("Adding bar to", n);
}

@foo() @bar() fn testing() {}
17 changes: 17 additions & 0 deletions examples/loops.saturn
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
let { entries } = require("../src/assets/std");

let tbl = {
a: 1,
b: true,
c: "x"
};

// For-each
for (k, v) in entries(tbl) {
print(k, v);
}

// Range based for
for i in 1..4 {
print(i);
}
68 changes: 68 additions & 0 deletions examples/oop.saturn
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// Example of OOP possible uses with std
let { abstract, entries, mixin, trait, impl } = require("../src/assets/std");

// Simple abstract class example.
class SimpleAbstract {
@abstract() fn example(self) {}
fn inherited(self) {
print("This was inherited " ++ self.name);
}
}

@mixin(SimpleAbstract)
class Simple {
fn example(self) {
print("Won't blow.");
}
fn run() {
let example = Simple { name: "Simple example" };
example.example();
example.inherited();
}
}
Simple::run();

// Trait example
@trait()
class TraitLike {
fn foo(self) {}
}

@impl(TraitLike)
class Implementor {
fn me(self) {
return "Implementor";
}
fn foo(self) {
print("The foo be like: " ++ self.me());
}
}

// Mixin examples
@mixin(Implementor)
class Child {
fn me(self) {
return "The child";
}
}

class BeMe {
fn bar(self) {
return "Amogus";
}
}

@mixin(BeMe)
@mixin(Child)
class MonsterJack {
fn me(self) {
return "Sus town? " ++ self.bar();
}
}

let child = Child {};
let imp = Implementor {};
let monster = MonsterJack {};
imp.foo();
child.foo();
monster.foo();
32 changes: 25 additions & 7 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,22 @@ print(consumer.consume(foo));
print(consumer.consume(bar));
```

Also you can decorate the code:
```rs
@bar()
class Foo {
@foo()
fn func(self) {
return "me";
}
}

@test()
fn suite() {
print("Yay!");
}
```

## Why replace Lua?

I like many aspects of Lua, specially how fast and lightweight the VM is. But
Expand All @@ -323,11 +339,13 @@ make the scripts less verbose and more easy to write.
Aside of the [Language Basics](#language-basics) section, there are other key
aspects of the language:

- Decorators!
- A built-in prelude library for runtime type checks.
- ~~Nice string interpolation.~~ (Maybe not?)
- Terser loops.
- Built-in operator overloading.
- Custom operators.
- Decorators
- Classes
- A built-in prelude library for runtime type checks and other things.
- Char expansion
- Macros
- Cooler lambdas.
- Terser loops
- Custom operators
- Some [RTTI](https://en.wikipedia.org/wiki/Run-time_type_information) (Which
enables reflection).
enables reflection)
Loading

0 comments on commit 42311a1

Please sign in to comment.