diff options
Diffstat (limited to 'docs/namespaces.md')
-rw-r--r-- | docs/namespaces.md | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/docs/namespaces.md b/docs/namespaces.md new file mode 100644 index 00000000..f00c692a --- /dev/null +++ b/docs/namespaces.md | |||
@@ -0,0 +1,71 @@ | |||
1 | # Namespaces | ||
2 | |||
3 | The LuaRocks.org repository allows for each user to published their own | ||
4 | collection of rocks. Since LuaRocks 3, this concept of per-user rocks has been | ||
5 | integrated into the tool, in the form of **namespaces**. | ||
6 | |||
7 | What you can do with namespaces: | ||
8 | |||
9 | * Install packages using a namespace: | ||
10 | * `luarocks install my_user/my_rock` | ||
11 | * Depend on a specific namespaced version of a rock in your rockspec: | ||
12 | * `dependencies = { "my_user/my_rock > 2.0" }` | ||
13 | |||
14 | ## Background | ||
15 | |||
16 | LuaRocks has always supported multiple repositories, which can be set in the | ||
17 | [config file](config_file_format.md) with the `rocks_servers` entry. A | ||
18 | repository is an address (a local directory or a remote URL) where LuaRocks | ||
19 | can find a `manifest-5.x` file and .rock and .rockspec files. We also call | ||
20 | such repository a "manifest", for short. | ||
21 | |||
22 | The [LuaRocks.org](LuaRocks.org)(LuaRocks.org)(https://luarocks.org) website | ||
23 | features a root manifest at `https://luarocks.org` as well as per-user | ||
24 | manifests at `https://luarocks.org/manifests/<your-user-name>`. Entries in the | ||
25 | root manifest are operated in a first-come first-served manner, but even if | ||
26 | someone else has already taken a rock name, you can upload your own version of | ||
27 | it to your user manifest. You can refer to a per-user manifest the same way as | ||
28 | any other rocks server, adding to your configuration or using it with the | ||
29 | `--server` flag. This means that you were always able to install your own | ||
30 | version of a rock using a command such as `luarocks install <my-rock> | ||
31 | --server=https://luarocks.org/manifests/<your-user-name>`. However, you could | ||
32 | not specifically depend on it from another rockspec, and once installed, the | ||
33 | information that this rock came from a specific manifest was lost. With | ||
34 | namespaces, now you can! | ||
35 | |||
36 | ## Using namespaces | ||
37 | |||
38 | All `luarocks` commands that accept a rock name as command line argument can | ||
39 | now take a namespaced variant: | ||
40 | |||
41 | ``` | ||
42 | luarocks install my_user/my_rock | ||
43 | ``` | ||
44 | |||
45 | LuaRocks will take your `rocks_trees` configuration and search for namespaced | ||
46 | manifests on each entry: for example, given the default server | ||
47 | `https://luarocks.org` it will look in | ||
48 | `https://luarocks.org/manifests/my_user`. | ||
49 | |||
50 | When installing, LuaRocks will internally store the information that this copy | ||
51 | of `my_rock` came from the `my_user` namespace, so it will be able to use that | ||
52 | information when another rockspec specifically asks for `my_user/my_rock` in | ||
53 | its dependencies. (The namespace information is stored in a separate | ||
54 | `rock_namespace` metadata file, at | ||
55 | `lib/luarocks/rocks-5.x/my_rock/1.0-1/rock_namespace`, relative to your local | ||
56 | rocks tree.) | ||
57 | |||
58 | ## Compatibility between non-namespaced and namespaced rocks | ||
59 | |||
60 | A namespaced package can stand for a non-namespaced one. If you have | ||
61 | `my_user/my_rock 1.0` installed and a rock depends on `my_rock 1.0`, the | ||
62 | installed rock will satisfy the dependency. | ||
63 | |||
64 | The opposite is not true: if you have `my_rock 1.0` installed but that did not | ||
65 | come from a `my_user` namespace, it will not satisfy a dependency for | ||
66 | `my_user/my_rock`. | ||
67 | |||
68 | ## Current limitations | ||
69 | |||
70 | You cannot have two rocks with the same name and version but different | ||
71 | namespaces installed at the same time in the same local rocks tree. | ||