Running K/ngnk: Difference between revisions
Subsetpark (talk | contribs) No edit summary |
Subsetpark (talk | contribs) No edit summary |
||
Line 23:
Roughly, including external libraries into ngn/k programs consists of three steps:
Note that <code>k.h</code> and <code>libk.so</code> must be available to your compiler and linker, respectively:
(The AUR package above installs both of the required files into the standard system directories)
|
Latest revision as of 01:15, 29 June 2024
Installing ngn/k[edit]
Linux package managers[edit]
Arch et al.[edit]
ngn/k is available on the AUR package manager; thus it can be conveniently installed on Arch Linux and related distros, like Manjaro.
Compiling from source[edit]
The ngn/k repo contains a makefile that will build an executable k
binary. Run make
to build k
, which you can then put into your PATH
.
It also contains repl.k
, which when run provides a convenient REPL environment for interactive programming. It's convenient to add a simple alias such as the following:
alias krepl='rlwrap k ~/sources/k/repl.k'
Building external libraries[edit]
ngn/k provides a k.h
header file. When this file is included, it describes an interface that C programs can implement in order to provide shared objects that are linkable from K programs.
Roughly, including external libraries into ngn/k programs consists of three steps:
- Write a K-compatible C program by including the
k.h
header - Compile the C program into a shared object file
- Inside of a K program, load the shared object file and assign it to a verb.
Note that k.h
and libk.so
must be available to your compiler and linker, respectively:
k.h
is available in the ngn/k source code;- The ngn/k makefile includes a target to build
libk.so
.
(The AUR package above installs both of the required files into the standard system directories)
References and Examples[edit]
Onikuruma[edit]
onikuruma is an implementation of the Oniguruma regular expression library for K. It contains both the required C code and Makefile as examples of how to build K-compatible external libraries, as well as example K code for how to call an external library from K. A short example for reference:
m:`"./libregex.so"2:(`match;2)
m["asd";"someasdstring"]