Skip to content

Commit 95df33a

Browse files
committed
update docs
1 parent 5c8eda9 commit 95df33a

File tree

1 file changed

+42
-38
lines changed

1 file changed

+42
-38
lines changed

Diff for: README.md

+42-38
Original file line numberDiff line numberDiff line change
@@ -10,49 +10,53 @@ Only works on the `extensions` branch of https://github.com/dvkt/ldpl
1010
Usage
1111
-----
1212

13-
For readline-like behavior, first set the `RL-PROMPT` text variable to a prompt then call the `RL-ACCEPT` subroutine:
13+
Any LDPL program using this extension must declare these three variables, even if you're not going to use them:
1414

15-
STORE "Type something: " IN RL-PROMPT
16-
CALL RL-ACCEPT
17-
18-
What the user inputs will be put into the `RL-INPUT` text variable:
19-
20-
DISPLAY "You entered: " RL-INPUT CRLF
15+
DATA:
16+
RL-INPUT is TEXT
17+
RL-PROMPT is TEXT
18+
RL-HISTORY-FILE is TEXT
2119

22-
To save and load history, first set the `RL-HISTORY-FILE` text variable to the location of your history file, then use the `RL-LOAD-HISTORY` and `RL-SAVE-HISTORY` subroutines to load/save the history and the `RL-ADD-HISTORY` subroutine to add the value of `RL-INPUT` to the current history:
20+
- `RL-INPUT` will be filled with the user's input after prompting them.
21+
- `RL-PROMPT` will default to `> ` and allows you to customize the prompt shown to users. Optional.
22+
- `RL-HISTORY-FILE` can be set by you to the location of the history file for this program. Optional.
2323

24-
STORE "history.txt" IN RL-HISTORY
25-
CALL RL-LOAD-HISTORY
26-
# code that calls RL-ACCEPT
27-
CALL RL-ADD-HISTORY
28-
# then, before you exit:
29-
CALL RL-SAVE-HISTORY
24+
To actually use the library, call the `RL-ACCEPT` subroutine to prompt the user for input:
3025

31-
Setup
32-
-----
26+
STORE "Type something: " IN RL-PROMPT
27+
CALL EXTERNAL RL-ACCEPT
3328

34-
To build a static archive for your platform, cd into this repo and run:
29+
What the user inputs will be put into the `RL-INPUT` text variable:
3530

36-
make
31+
DISPLAY "You entered: " RL-INPUT CRLF
3732

38-
This will create `ldplnoise.a`. Copy that file and `ldplnoise.h` into your LDPL project's root directory.
33+
So the above will print:
3934

40-
Then compile your LDPL project:
35+
Type something: <user types Dave and presses >
36+
You entered: Dave
4137

42-
ldpl -i=ldplnoise.h your-code.ldpl
38+
To record history for a single session, call `RL-ADD-HISTORY` after calling `RL-ACCEPT`. The content of the `RL-INPUT` variable will be added to the history.
4339

44-
You can test that the archive was created correctly by compiling `test.lsc` in this repo:
40+
To persist history across sessions, you need to save and load a history file. To do so, first set the `RL-HISTORY-FILE` text variable to the location of your history file, then use the `RL-LOAD-HISTORY` and `RL-SAVE-HISTORY` subroutines to load/save the history when your LDPL program begins and ends:
4541

46-
ldpl -i=ldplnoise.h test.lsc
47-
./test-bin
42+
# ...program starts...
43+
STORE "history.txt" IN RL-HISTORY
44+
CALL EXTERNAL RL-LOAD-HISTORY
45+
# ...main program code...
46+
CALL EXTERNAL RL-ACCEPT
47+
CALL EXTERNAL RL-ADD-HISTORY
48+
# ...before the program exits...
49+
CALL EXTERNAL RL-SAVE-HISTORY
4850

49-
Most likely you'll want to include this entire repo in your LDPL project and, in your build process, create an archive using the following commands:
51+
Setup
52+
-----
5053

51-
c++ -c linenoise.hpp -std=gnu++11 -o linenoise.o
52-
c++ -c ldplnoise.cpp -std=gnu++11 -o ldplnoise.o
53-
ar -cvq ldplnoise.a ldplnoise.o linenoise.o
54+
The easy way to include LDPLNOISE in your project is to just clone this repo into it and tell the the `ldpl` compiler where to find `ldplnoise.cpp`:
5455

55-
Then pass -i=ldplnoise.h to `ldpl` when compiling your project.
56+
cd my-great-ldpl-project
57+
git clone https://github.com/dvkt/ldplnoise
58+
ldpl -i=ldplnoise/ldplnoise.cpp my-code.ldpl
59+
./my-code-bin
5660

5761
Example
5862
-------
@@ -63,21 +67,21 @@ Example
6367

6468
This should launch you into a basic prompt that echos what you type and remembers you history for that session. To exit, just type "quit" or "exit", submit an empty line, or hit Ctrl-C.
6569

66-
Check out `test.lsc` to see an example of using the extension.
70+
Check out `test.ldpl` to see an example of using the extension.
6771

6872
LDPL API
6973
--------
7074

7175
Variables:
7276

73-
RL-PROMPT is TEXT
74-
RL-INPUT is TEXT
75-
RL-HISTORY-FILE is TEXT
77+
RL-PROMPT is TEXT # prompt shown to user
78+
RL-INPUT is TEXT # the user's input after a RL-ACCEPT
79+
RL-HISTORY-FILE is TEXT # path to history file
7680

7781
Subroutines:
7882

79-
RL-ACCEPT
80-
RL-LOAD-HISTORY
81-
RL-SAVE-HISTORY
82-
RL-ADD-HISTORY
83-
83+
RL-ACCEPT # main readline()-like prompt function.
84+
RL-LOAD-HISTORY # load command history from RL-HISTORY-FILE
85+
RL-SAVE-HISTORY # save command history to RL-HISTORY-FFILE
86+
RL-ADD-HISTORY # add content of RL-INPUT to the history
87+
# should be called after RL-ACCEPT

0 commit comments

Comments
 (0)