2018-03-14 22:32:41 +03:00
## Working with libraries and modules
2020-11-19 23:12:17 +03:00
Carp comes with a standard library called [Core ](../core/ ) where only certain files are loaded by default (see [Core.carp ](../core/Core.carp )). If your `CARP_DIR` environment variable is [set properly ](https://github.com/carp-lang/Carp/blob/master/docs/Install.md#setting-the-carp_dir ), these libraries will be easily imported using the `load` command. For example, to get access to the Bench module, do the following:
2018-03-14 22:32:41 +03:00
```clojure
(load "Bench.carp")
```
2018-03-14 22:37:00 +03:00
Using the functions in the Bench module still requires pre-pending them with the module name, i.e. `(Bench.bench fib)` . To avoid that, also do `(use Bench)` .
2018-03-14 22:40:08 +03:00
To see what functions a certain module contains, use the `info` command:
```clojure
2018-10-22 22:22:25 +03:00
(info Bench)
2018-03-14 22:40:08 +03:00
```
2018-03-14 22:40:58 +03:00
External librares can be loaded by using their relative or absolute location in your file system as the path. To make a library publically available in a more general way you can add it to your Carp project's search path:s (found by running `:p` in the repl). For instance, here's how you would add the NCurses library so that it can be loaded with just `(load "NCurses.carp")` .
2018-03-14 22:32:41 +03:00
```clojure
(Project.config "search-path" "~/Projects/carp-ncurses")
```
2020-12-23 11:46:11 +03:00
This line of configuration can be put into [config.carp ](Manual.md#Profile-settings ) to make it apply in all your projects.
2018-03-14 22:32:41 +03:00
2018-10-25 17:07:34 +03:00
## Loading via git
2019-05-01 01:24:29 +03:00
You can also load libraries via Git like that:
2018-10-25 17:07:34 +03:00
2019-05-01 01:24:29 +03:00
```clojure
2019-05-20 15:14:22 +03:00
(load "git@github.com:hellerve/anima.carp@master")
2019-05-01 01:24:29 +03:00
```
This will download the [Anima ](https://github.com/hellerve/anima ) library to
`~/.carp/libs/<library>/<tag>` and load the file `anima.carp` in it. To get a
stable version of the library you should specify a git tag rather than
`@master` .
2018-10-25 17:07:34 +03:00
2019-06-06 11:03:51 +03:00
If you want to make a library ready for loading, either prepare a file that has the same name
2019-05-01 01:24:29 +03:00
as the library—in the case above, `anima.carp` —or a file called `main.carp` as
an entrypoint.
2018-10-25 17:07:34 +03:00
2019-06-06 11:04:54 +03:00
Please note that for private repos only loading through SSH is supported. For public repos you can use HTTPS:
2019-06-06 11:03:51 +03:00
```clojure
(load "https://github.com/hellerve/anima@master")
```
2020-11-19 23:10:22 +03:00
## Documentation
You can generate HTML documentation for a set of modules by running `save-docs` in the REPL:
```clojure
> (save-docs Int Float String)
```
See the file [generate_core_docs.carp ](./core/generate_core_docs.carp ) for an example of how to configure the result.
2020-11-20 10:24:36 +03:00
## Auto generated API documentation
* [Core ](http://carp-lang.github.io/carp-docs/core/core_index.html )
* [SDL ](http://carp-lang.github.io/carp-docs/sdl/SDL_index.html )
2020-11-19 23:10:22 +03:00
## Some External Libraries
* [Anima ](https://github.com/hellerve/anima ) (A simple drawing and animation framework)
2017-12-15 21:58:02 +03:00
* [Stdint ](https://github.com/hellerve/stdint ) (A wrapper around the types defined in stdint.h)
* [Socket ](https://github.com/hellerve/socket ) (A wrapper around C sockets)
* [Physics ](https://github.com/hellerve/physics ) (A port of phys.js)
2018-03-15 11:08:55 +03:00
* [NCurses ](https://github.com/eriksvedang/carp-ncurses ) ([https://www.gnu.org/software/ncurses/](https://www.gnu.org/software/ncurses/))
2018-03-24 17:34:01 +03:00
* [Curl ](https://github.com/eriksvedang/carp-curl ) (Simple bindings to the Curl library)
2018-11-06 22:20:07 +03:00
For a growing list of Carp packages, see [Carpentry ](https://github.com/carpentry-org ).
2020-11-19 23:10:22 +03:00
Do you have a library that you want to plug here? Pleas make a PR!