Skip to content

Commit a5f7be9

Browse files
Sainanwell-in-that-case
authored andcommitted
Add packages page
1 parent a9bbdb6 commit a5f7be9

File tree

4 files changed

+53
-3
lines changed

4 files changed

+53
-3
lines changed

docs/Changelog.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
sidebar_position: 12
2+
sidebar_position: 13
33
---
44

55
This page contains the changelogs from all [releases of Pluto](https://github.com/PlutoLang/Pluto/releases).

docs/Compatibility.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
sidebar_position: 10
2+
sidebar_position: 11
33
---
44

55
Pluto aims to be source- and bytecode-compatible with existing Lua code such that it can simply be used as a drop-in replacement for Lua, and Lua modules can simply be used in Pluto codebases. In the vast majority of cases, we do succeed, but there are a few things to be aware of.

docs/For Integrators.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
sidebar_position: 11
2+
sidebar_position: 12
33
---
44

55
# For Integrators

docs/Packages.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
---
2+
sidebar_position: 10
3+
---
4+
5+
This document will explain how external libraries are handled in Pluto and give some recommendations for their usage.
6+
7+
## How `require` locates files
8+
9+
By default, `require` only checks the installation directory and current working directory for a matching file or an `init` file in a subfolder matching the requested name.
10+
11+
So, if you want to `require` a file in the same working directory, e.g. `mylib`, it has to be in one of these places:
12+
- `./mylib.lua`
13+
- `./mylib/init.lua`
14+
- `./mylib.pluto`
15+
- `./mylib/init.pluto`
16+
17+
Notably, there is no standardized `lib` or `modules` folder. However, you can update `package.path` to check such folders as well:
18+
```pluto norun
19+
package.path ..= package.config[3].."lib"..package.config[1].."?.pluto"
20+
```
21+
With this, we could for example have `mylib` located at `./lib/mylib.pluto`.
22+
23+
## An approach to package management
24+
25+
While it is perfectly viable to grab some pre-existing code from the internet and drop it somewhere in your project, there is often no "chain of custody", causing this code to never receive updates and making it harder to report bugs in the right place.
26+
27+
Our solution for this is [APM](https://github.com/PlutoLang/apm#readme), short for Agnostic Package Manager. It is agnostic in the sense that it can be used for non-Pluto projects and dependencies as well.
28+
29+
The way you use APM is by creating Pluto script that loads APM and then describes dependencies using its Pluto-based configuration format:
30+
```pluto norun title="deps.pluto"
31+
;(require"http".request"//use.agnostic.pm"|>load)()
32+
33+
git "https://github.com/PlutoLang/pluto-dns"
34+
from "dns.pluto" to "dns.pluto"
35+
```
36+
After running the `deps.pluto` script, you will find the `dns.pluto` file in your working directory, so you can proceed to use it:
37+
```pluto norun title="index.pluto"
38+
local dns = require "dns"
39+
local resolver = new dns.httpresolver()
40+
print(resolver:query("A", "testrr-1337.soup.do")[1].ip) --> 1.3.3.7
41+
```
42+
To later update your dependencies, simply run `deps.pluto` again. [Learn more...](https://github.com/PlutoLang/apm#readme)
43+
44+
## Noteworthy packages for Pluto
45+
46+
While Pluto's standard library is still growing, a few packages are available to provide what is currently missing:
47+
- [iniparser](https://github.com/calamity-inc/iniparser) — INI reader & writer for Lua 5.3+ and Pluto
48+
- [pluto-websocket](https://github.com/PlutoLang/pluto-websocket) — expands Pluto's `socket` library with WebSocket client functionality
49+
- [pluto-dns](https://github.com/PlutoLang/pluto-query) — expands Pluto's `xml` library with query selector functionality
50+
- [pluto-dns](https://github.com/PlutoLang/pluto-dns) — DNS client library

0 commit comments

Comments
 (0)