https://github.com/nyxcode/ketamine
embedded dynamically typed scripting language
https://github.com/nyxcode/ketamine
Last synced: about 1 month ago
JSON representation
embedded dynamically typed scripting language
- Host: GitHub
- URL: https://github.com/nyxcode/ketamine
- Owner: NyxCode
- Created: 2020-03-25T02:44:44.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2023-01-20T22:30:33.000Z (about 3 years ago)
- Last Synced: 2025-07-04T20:20:47.120Z (8 months ago)
- Language: Rust
- Size: 766 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 24
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# ketamine
dynamic embeddable scripting language, written in rust.
### types
```
integer = 1;
float = 3.14;
boolean = true;
string = "hello world!";
array = [1, 2, 3];
object = { key: "value" };
fib = function(n) {
if (n < 3) {
1
} else {
fib(n - 2) + fib(n - 1)
}
};
```
### control flow
```
age = if (person.age < 15) {
"child"
} else if (person.age < 18) {
"adolescent"
} else {
"adult
};
```
```
for (person in people) {
print("Hello", person.first_name);
};
```
```
result = while (true) {
next = try_again();
if (next != null) {
break next;
};
}
```
### features
- embeddable & extendable
```rust
fn abs(this: i64, args: Vec) -> Result {
Ok(Value::Integer(this.abs()))
}
interpreter.prototype_function("abs", abs);
assert_eq!(interpreter.eval("-10.abs()").unwrap() == Value::Integer(10));
```
- first-class functions
- implicit `return`
```
with_return = function() { return 1; };
without_return = function() { 1 };
```
- implicit `this`
```
counter = {
count: 0,
increment: function() {
this.count = this.count + 1;
}
};
counter.increment();
```
- extend types using prototypes
```
$integer.abs = function() {
if (this < 0) {
-this
} else {
this
}
}
```
- range expressions
```
for (x in 0..10) { ... };
```