Skip to content

Commit

Permalink
Added Janet support
Browse files Browse the repository at this point in the history
  • Loading branch information
scambier committed Feb 24, 2023
1 parent 197af05 commit e5cd14b
Show file tree
Hide file tree
Showing 8 changed files with 419 additions and 81 deletions.
402 changes: 334 additions & 68 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Cargo.toml
Expand Up @@ -2,7 +2,7 @@
authors = ["Simon Cambier <simon.cambier@protonmail.com>"]
edition = "2018"
name = "tq-bundler"
version = "2.1.1"
version = "2.2.0"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand Down
10 changes: 8 additions & 2 deletions README.md
Expand Up @@ -26,7 +26,7 @@ $ tq-bundler.exe run game.lua main.lua --tic tic80.exe
- [x] Builds all your files into a single bundle
- [x] Watches changes to rebuild automatically
- [x] Launches your game inside TIC-80
- [x] Supports Lua, Moonscript, Fennel, Wren, Squirrel, JavaScript and Ruby
- [x] Supports Lua, Moonscript, Fennel, Janet, Wren, Squirrel, JavaScript and Ruby

## Installation

Expand All @@ -44,7 +44,7 @@ TQ-Bundler has 2 sub-commands:
```bash
$ mkdir my-game
$ cd my-game
$ tq-bundler.exe init lua # or moon, wren, fennel, squirrel, js, ruby
$ tq-bundler.exe init lua # or moon, wren, fennel, janet, squirrel, js, ruby
```

This will create the files `game.lua` (containing the sprites and sounds) and `main.lua` (the code entry point)
Expand All @@ -69,6 +69,12 @@ include "tools.utils" -- ./tools/utils.moon
(include "tools.utils") ;; ./tools/utils.fnl
```

```janet
# Janet syntax
(include "macros") # ./macros.janet
(include "tools.utils") # ./tools/utils.janet
```

```c
// Wren syntax
include "macros" // ./macros.wren
Expand Down
23 changes: 15 additions & 8 deletions src/config.rs
Expand Up @@ -20,30 +20,37 @@ impl FileType {
// (\n|[\r\n]+) is a fix for the EOL symbol ($) not working on Windows CRLF

// Regex for `include "my.module"`
let regex = Regex::new(r#"(?m)^include "([a-zA-Z\-_\.]+)"(\n|[\r\n]+)"#).unwrap();
let default_regex = Regex::new(r#"(?m)^include "([a-zA-Z\-_\.]+)"(\n|[\r\n]+)"#).unwrap();

// Regex for `(include "my.module")`
let list_regex = r#"(?m)^\(include "([a-zA-Z\-_\.]+)"\)(\n|[\r\n]+)"#;

let ext = filename.extension().unwrap().to_str().unwrap();
let extension = ext.to_string();
match ext {
"lua" | "moon" => FileType {
extension,
regex,
regex: default_regex,
comment: "--".to_string(),
},
"fnl" => FileType {
extension,
// Regex for `(include "my.module")`
regex: Regex::new(r#"(?m)^\(include "([a-zA-Z\-_\.]+)"\)(\n|[\r\n]+)"#).unwrap(),
comment: ";;".to_string(),
regex: Regex::new(list_regex).unwrap(),
comment: "#".to_string(),
},
"janet" => FileType {
extension,
regex: Regex::new(list_regex).unwrap(),
comment: "#".to_string(),
},
"wren" => FileType {
extension,
regex,
regex: default_regex,
comment: "//".to_string(),
},
"rb" => FileType {
extension,
regex,
regex: default_regex,
comment: "#".to_string(),
},
"nut" | "js" => FileType {
Expand All @@ -54,7 +61,7 @@ impl FileType {
},
_ => {
log(format!(
"Supported extensions are .lua, .moon, .fnl, .wren, .nut, .js, .rb"
"Supported extensions are .lua, .moon, .fnl, .wren, .nut, .js, .rb, .janet"
));
exit(1);
}
Expand Down
31 changes: 31 additions & 0 deletions src/init/janet/game.janet
@@ -0,0 +1,31 @@
# script: janet

# <TILES>
# 001:eccccccccc888888caaaaaaaca888888cacccccccacc0ccccacc0ccccacc0ccc
# 002:ccccceee8888cceeaaaa0cee888a0ceeccca0ccc0cca0c0c0cca0c0c0cca0c0c
# 003:eccccccccc888888caaaaaaaca888888cacccccccacccccccacc0ccccacc0ccc
# 004:ccccceee8888cceeaaaa0cee888a0ceeccca0cccccca0c0c0cca0c0c0cca0c0c
# 017:cacccccccaaaaaaacaaacaaacaaaaccccaaaaaaac8888888cc000cccecccccec
# 018:ccca00ccaaaa0ccecaaa0ceeaaaa0ceeaaaa0cee8888ccee000cceeecccceeee
# 019:cacccccccaaaaaaacaaacaaacaaaaccccaaaaaaac8888888cc000cccecccccec
# 020:ccca00ccaaaa0ccecaaa0ceeaaaa0ceeaaaa0cee8888ccee000cceeecccceeee
# </TILES>

# <WAVES>
# 000:00000000ffffffff00000000ffffffff
# 001:0123456789abcdeffedcba9876543210
# 002:0123456789abcdef0123456789abcdef
# </WAVES>

# <SFX>
# 000:000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000304000000000
# </SFX>

# <TRACKS>
# 000:100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
# </TRACKS>

# <PALETTE>
# 000:1a1c2c5d275db13e53ef7d57ffcd75a7f07038b76425717929366f3b5dc941a6f673eff7f4f4f494b0c2566c86333c57
# </PALETTE>

27 changes: 27 additions & 0 deletions src/init/janet/main.janet
@@ -0,0 +1,27 @@
# title: game title
# author: game developer, email, etc.
# desc: short description
# site: website link
# license: MIT License (change this to your license of choice)
# version: 0.1
# script: janet
# strict: true

# Unlike other langauges, the tic80 API
# is provided as a module.
(import tic80)

(var t 0)
(var x 96)
(var y 24)

(defn TIC []
(when (tic80/btn 0) (-- y))
(when (tic80/btn 1) (++ y))
(when (tic80/btn 2) (-- x))
(when (tic80/btn 3) (++ x))
(tic80/cls 13)
(tic80/spr (if (> (% t 60) 30) 1 3)
x y 14 3 0 0 2 2)
(tic80/print "HELLO WORLD!" 84 84)
(++ t))
3 changes: 2 additions & 1 deletion src/initializer.rs
Expand Up @@ -13,13 +13,14 @@ pub fn initialize(lang: &str) {
"lua" => "lua",
"moonscript" | "moon" => "moon",
"fennel" | "fnl" => "fnl",
"janet" => "janet",
"squirrel" | "nut" => "nut",
"wren" => "wren",
"javascript" | "js" => "js",
"ruby" | "rb" => "rb",
_ => {
log(
r#"Invalid file type. Use "lua", "moon, "fennel", "squirrel", "wren", "js", "rb"#
r#"Invalid file type. Use "lua", "moon, "fennel", "squirrel", "wren", "js", "rb", "janet"#
.to_string(),
);
exit(1);
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Expand Up @@ -67,7 +67,7 @@ fn main() {
Arg::new("LANG")
.required(true)
.index(1)
.help(r#""lua", "moon", "fennel", "wren", "squirrel", "js", "ruby"#)
.help(r#""lua", "moon", "fennel", "wren", "squirrel", "js", "ruby", "janet"#)
)
)
.get_matches();
Expand Down

0 comments on commit e5cd14b

Please sign in to comment.