Adds information and support for global modules
This commit is contained in:
parent
53bd3bbc99
commit
a2fc5f8b70
7
Makefile
7
Makefile
|
@ -4,6 +4,7 @@ PREFIX := /usr/local
|
|||
EXEC_PREFIX := ${PREFIX}
|
||||
BINDIR := ${EXEC_PREFIX}/bin
|
||||
DATAROOTDIR := ${PREFIX}/share
|
||||
LIBDIR := ${PREFIX}/lib
|
||||
MANDIR := ${DATAROOTDIR}/man
|
||||
MAN1DIR := ${MANDIR}/man1
|
||||
VERSION := $(shell git rev-list HEAD --count)
|
||||
|
@ -14,13 +15,17 @@ build:
|
|||
${GOCMD} build -ldflags "-w -s -X main.VersionHash=${VERSION_HASH}" -o ${BINARY}
|
||||
|
||||
.PHONY: install
|
||||
install: install-bin install-man clean
|
||||
install: install-bin install-man install-module-dir clean
|
||||
|
||||
.PHONY: install-bin
|
||||
install-bin: build
|
||||
install -d ${DESTDIR}${BINDIR}
|
||||
install -m 0755 ./${BINARY} ${DESTDIR}${BINDIR}
|
||||
|
||||
.PHONY: install-module-dir
|
||||
install-module-dir:
|
||||
mkdir -p ${DESTDIR}${LIBDIR}/slope/modules
|
||||
|
||||
.PHONY: install-man
|
||||
install-man: ${BINARY}.1
|
||||
gzip -k ./${BINARY}.1
|
||||
|
|
|
@ -494,9 +494,13 @@ slope has a basic module system. When you use the `load` procedure you are loadi
|
|||
1. `$SLOPE_MOD_PATH`
|
||||
2. `$XDG_DATA_HOME/slope/modules`
|
||||
3. `~/.local/share/slope/modules`
|
||||
4. `/usr/local/lib/slope/modules`
|
||||
|
||||
So, a hypethetical module named `test` would be found at `~/.local/share/slope/modules/test`.
|
||||
|
||||
Note that the fourth item, above, is the global (systemi-wide) module directory. `slp` can install modules to this directory by passing the `-g` or `--global` flag while acting as a user that has access to writing files in the `/usr/local` heirarchy. You may, alternately, clone modules directly to this path. A local module will always be used before a global module.
|
||||
|
||||
|
||||
### slp
|
||||
|
||||
slope has a package manager available at [https://git.rawtext.club/slope-lang/slp](https://git.rawtext.club/slope-lang/slp). Once installed you will be able to search/browse packages, install, remove, and update things, generate new module skeletons, read docs, etc. The slp repository has information on how to get modules added to the package registry. This is, at present, the best way to deal with modules and is highly recommended but by no means required. The same thing can be done by finding a repository with a module and cloning it to your module path. So long as it is a valid module it will be loadable with `load-mod`.
|
||||
|
|
|
@ -560,7 +560,6 @@ func stringParensMatch(s string) bool {
|
|||
return true
|
||||
}
|
||||
|
||||
//
|
||||
func variadic(l expression) int {
|
||||
list, ok := l.([]expression)
|
||||
if !ok || len(list) == 0 {
|
||||
|
|
14
main.go
14
main.go
|
@ -14,6 +14,8 @@ import (
|
|||
ln "github.com/peterh/liner"
|
||||
)
|
||||
|
||||
const globalLibPath = "/usr/local/lib/slope/modules/"
|
||||
|
||||
var openFiles []*IOHandle
|
||||
var replCounter int = 0
|
||||
var line *ln.State
|
||||
|
@ -85,6 +87,7 @@ func Init() {
|
|||
ModBaseDir = ExpandedAbsFilepath(getModBaseDir())
|
||||
PreloadDir = ExpandedAbsFilepath(getPreloadDir())
|
||||
createDataDirs(ModBaseDir)
|
||||
createDataDirs(globalLibPath)
|
||||
createDataDirs(PreloadDir)
|
||||
c := make(chan os.Signal)
|
||||
signal.Notify(c, syscall.SIGINT)
|
||||
|
@ -161,6 +164,7 @@ func RunCommand(s string) {
|
|||
}
|
||||
|
||||
func RunModule(path string, relative bool) (env, error) {
|
||||
modDir := ModBaseDir
|
||||
modEnv := env{make(map[symbol]expression), &globalenv}
|
||||
revertToThisDir, err := os.Getwd()
|
||||
if err != nil {
|
||||
|
@ -171,11 +175,15 @@ func RunModule(path string, relative bool) (env, error) {
|
|||
var s string
|
||||
if !relative {
|
||||
// This branch is run from 'load-mod'
|
||||
err = os.Chdir(filepath.Join(ModBaseDir, path))
|
||||
err = os.Chdir(filepath.Join(modDir, path))
|
||||
if err != nil {
|
||||
return modEnv, err
|
||||
err = os.Chdir(filepath.Join(globalLibPath, path))
|
||||
if err != nil {
|
||||
return modEnv, err
|
||||
}
|
||||
modDir = globalLibPath
|
||||
}
|
||||
fp := filepath.Join(ModBaseDir, path, "main.slo")
|
||||
fp := filepath.Join(modDir, path, "main.slo")
|
||||
b, err := ioutil.ReadFile(fp)
|
||||
if err != nil {
|
||||
_ = os.Chdir(revertToThisDir)
|
||||
|
|
2
slope.1
2
slope.1
|
@ -41,6 +41,8 @@ Install the module pointed to by \fIurl\fP to the slope module path. \fB-install
|
|||
.TP
|
||||
The \fBslope\fP module path can be defined by setting the variable \fI$SLOPE_MOD_PATH\fP. If that variable is not defined \fBslope\fP will fall back to \fI$XDG_DATA_HOME/slope/modules\fP or \fI~/.local/share/slope/modules\fP. This is where \fBslope\fP will look for modules when the procedure \fIload-mod\fP is called.
|
||||
.TP
|
||||
Global/system-wide modules should be installed to \fI/usr/local/lib/slope/modules\fP. slope will always use a user-local module if one exists; if not then slope will search the global modules heirarchy.
|
||||
.TP
|
||||
The \fBslope\fP preload directory can be defined by setting the variable \fI$SLOPE_PRELOAD_DIR\fP. If that variable is not defined \fBslope\fP will fall back to \fI$XDG_DATA_HOME/slope/preload\fP or \fI~/.local/share/slope/preload\fP. This is where \fBslope\fP will look for files to evaluate when the \fI-L\fP flag is passed at runtime.
|
||||
.TP
|
||||
REPL session history is persistent in \fBslope\fP. The history file is located one directory up from the \fBslope\fP module directory (whatever that is set to) and named \fIslope-repl.history\fP, for example: \fI$SLOPE_MOD_PATH/../slope-repl.history\fP (using a fallback path for \fI$SLOPE_MOD_PATH\fP if needed.
|
||||
|
|
Loading…
Reference in New Issue
Block a user