lune/README.md

215 lines
5.2 KiB
Markdown
Raw Normal View History

2023-01-19 19:57:39 +00:00
<!-- markdownlint-disable MD033 -->
2023-01-19 19:15:32 +00:00
# Lune 🌙
[![CI](https://github.com/filiptibell/lune/actions/workflows/ci.yaml/badge.svg)](https://github.com/filiptibell/lune/actions/workflows/ci.yaml)
[![Release](https://github.com/filiptibell/lune/actions/workflows/release.yaml/badge.svg)](https://github.com/filiptibell/lune/actions/workflows/release.yaml)
2023-01-24 18:42:07 +00:00
A standalone [Luau](https://luau-lang.org) script runner
2023-01-19 19:15:32 +00:00
---
🚀 Use the ergonomics and readability of Luau instead of shell scripts 🚀
[Full example & walkthrough](.lune/hello_lune.luau)
2023-01-19 19:57:39 +00:00
## ⚙️ Installation
2023-01-19 19:59:44 +00:00
The preferred way of installing Lune is using [Aftman](https://github.com/lpghatguy/aftman).
2023-01-19 19:57:39 +00:00
2023-01-19 19:59:44 +00:00
This will add `lune` to an `aftman.toml` file in the current directory, or create one if it does not exist:
2023-01-19 19:57:39 +00:00
```sh
aftman add filiptibell/lune
2023-01-19 19:57:39 +00:00
```
2023-01-19 20:08:38 +00:00
You can also download pre-built binaries for most systems directly from the GitHub Releases page.
2023-01-19 19:57:39 +00:00
## ✏️ Writing Lune Scripts
Check out the examples of how to write a script in the [.lune](.lune) folder !
2023-01-19 19:15:32 +00:00
<details>
2023-01-19 19:57:39 +00:00
<summary><b>🔎 Full list of APIs</b></summary>
2023-01-20 03:10:34 +00:00
<details>
<summary><b>console</b> - Logging & formatting</summary>
```lua
type console = {
resetColor: () -> (),
setColor: (color: "black" | "red" | "green" | "yellow" | "blue" | "purple" | "cyan" | "white") -> (),
resetStyle: () -> (),
setStyle: (color: "bold" | "dim") -> (),
format: (...any) -> (string),
log: (...any) -> (),
info: (...any) -> (),
warn: (...any) -> (),
error: (...any) -> (),
}
```
</details>
<details>
<summary><b>fs</b> - Filesystem</summary>
2023-01-19 19:57:39 +00:00
```lua
type fs = {
readFile: (path: string) -> string,
readDir: (path: string) -> { string },
writeFile: (path: string, contents: string) -> (),
writeDir: (path: string) -> (),
removeFile: (path: string) -> (),
removeDir: (path: string) -> (),
isFile: (path: string) -> boolean,
isDir: (path: string) -> boolean,
}
```
2023-01-20 03:10:34 +00:00
</details>
<details>
<summary><b>net</b> - Networking</summary>
2023-01-19 19:57:39 +00:00
```lua
type net = {
request: (config: string | {
url: string,
method: ("GET" | "POST" | "PUT" | "DELETE" | "HEAD" | "OPTIONS" | "PATCH")?,
headers: { [string]: string }?,
body: string?,
}) -> {
ok: boolean,
statusCode: number,
statusMessage: string,
headers: { [string]: string },
body: string,
},
jsonEncode: (value: any, pretty: boolean?) -> string,
jsonDecode: (encoded: string) -> any,
2023-01-19 19:57:39 +00:00
}
```
2023-01-20 03:10:34 +00:00
</details>
<details>
<summary><b>process</b> - Current process & child processes</summary>
2023-01-19 19:57:39 +00:00
```lua
type process = {
args: { string },
env: { [string]: string? },
2023-01-19 19:57:39 +00:00
exit: (code: number?) -> (),
spawn: (program: string, params: { string }?) -> {
ok: boolean,
code: number,
stdout: string,
stderr: string,
},
}
```
</details>
2023-01-24 00:14:41 +00:00
<details>
<summary><b>task</b> - Task scheduler & thread spawning</summary>
```lua
type task = {
cancel: (thread: thread) -> (),
2023-01-24 17:31:25 +00:00
defer: <T...>(functionOrThread: thread | (T...) -> (...any), T...) -> thread,
delay: <T...>(duration: number?, functionOrThread: thread | (T...) -> (...any), T...) -> thread,
spawn: <T...>(functionOrThread: thread | (T...) -> (...any), T...) -> thread,
2023-01-24 00:14:41 +00:00
wait: (duration: number?) -> (number),
}
```
</details>
2023-01-20 03:10:34 +00:00
</details>
2023-01-19 19:57:39 +00:00
<details>
2023-01-19 20:01:57 +00:00
<summary><b>🔀 Example translation from Bash</b></summary>
2023-01-19 19:15:32 +00:00
```bash
#!/bin/bash
VALID=true
COUNT=1
while [ $VALID ]
do
echo $COUNT
if [ $COUNT -eq 5 ];
then
break
fi
((COUNT++))
done
```
2023-01-19 20:01:57 +00:00
**_With Lune & Luau:_**
2023-01-19 19:15:32 +00:00
```lua
local valid = true
local count = 1
while valid do
print(count)
if count == 5 then
break
end
count += 1
end
```
</details>
2023-01-19 19:57:39 +00:00
<details>
<summary><b>🧑‍💻 Configuring VSCode for Lune</b></summary>
2023-01-19 19:15:32 +00:00
2023-01-19 19:57:39 +00:00
Lune puts developer experience first, and as such provides type definitions and configurations for several tools out of the box.
2023-01-19 19:15:32 +00:00
2023-01-19 19:57:39 +00:00
<details>
<summary>Luau LSP</summary>
2023-01-19 19:15:32 +00:00
2023-01-19 19:57:39 +00:00
1. Use `lune --download-luau-types` to download Luau types (`luneTypes.d.luau`) to the current directory
2023-01-24 16:27:20 +00:00
2. Set your definition files setting to include `luneTypes.d.luau`
3. Set the require mode setting to `relativeToFile`
En example of these settings can be found in the [.vscode](.vscode) folder in this repository
2023-01-19 19:15:32 +00:00
2023-01-19 19:57:39 +00:00
</details>
2023-01-19 19:15:32 +00:00
2023-01-19 19:57:39 +00:00
<details>
2023-01-24 16:27:20 +00:00
2023-01-19 19:57:39 +00:00
<summary>Selene</summary>
2023-01-19 19:15:32 +00:00
2023-01-19 19:57:39 +00:00
1. Use `lune --download-selene-types` to download Selene types (`lune.yml`) to the current directory
2023-01-24 16:27:20 +00:00
2. Use either `std = "luau+lune"`, or `std = "roblox+lune"` if your project also contains Roblox-specific code, in your `selene.toml` configuration file
2023-01-19 19:15:32 +00:00
2023-01-19 19:57:39 +00:00
</details>
2023-01-24 16:27:20 +00:00
<br>
2023-01-19 19:57:39 +00:00
**_NOTE:_** _It is highly recommended to add any type definition files to your `.gitignore` and to only download them using these commands, since this guarantees that you have type definitions compatible with your installed version of Lune._
2023-01-19 19:15:32 +00:00
2023-01-19 19:57:39 +00:00
</details>
2023-01-19 19:15:32 +00:00
## 🏃 Running Lune Scripts
After you've written a script file, for example `script-name.luau`, you can run it:
2023-01-19 19:15:32 +00:00
```sh
lune script-name
2023-01-19 19:15:32 +00:00
```
This will look for the file `script-name.luau` in a few locations:
2023-01-19 19:15:32 +00:00
- The current directory
- The folder `lune` in the current directory, if it exists
- The folder `.lune` in the current directory, if it exists
If you don't want Lune to look in sub-directories you can provide a full file path with the file extension included, instead of only the file name. <br>
---
**_NOTE:_** _Lune also supports files with the `.lua` extension but using the `.luau` extension is highly recommended._