Skip to content

Commit eb1289f

Browse files
committed
Readme updated for library instructions
1 parent 5236ef4 commit eb1289f

File tree

3 files changed

+40
-3
lines changed

3 files changed

+40
-3
lines changed

dub.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88
"name": "calcool",
99

1010
"configurations": [{
11-
"name": "cli_app",
11+
"name": "Cli_app",
1212
"targetType": "executable",
1313
"versions": ["CLI_APP"]
1414
},
1515
{
16-
"name": "library",
16+
"name": "Library",
1717
"targetType": "library",
1818
"versions": ["LIBRARY"]
1919
}

readme.md

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,45 @@ Usage: calcool [OPTION] [ARGUMENT]
2323

2424
### Use as a library
2525

26+
Add calcool to your dependencies
27+
28+
```json
29+
"dependencies": {
30+
"calcool": "~>1.2.0"
31+
}
32+
```
33+
34+
Set its subconfiguration to `Library`
35+
36+
```json
37+
"configurations": [{
38+
"name": "your app's name",
39+
"subConfigurations": {
40+
"calcool": "Library"
41+
}
42+
}]
43+
```
44+
45+
Use it in your app
46+
2647
```d
48+
import calcool.parser;
49+
2750
auto p = new Prser();
28-
string result = p.evaluateFromString("sin(45*2) - 22 * -exp(3)");
51+
52+
try {
53+
// You can call evaluateFromString as many times as you want
54+
string result = p.evaluateFromString("sin(45*2) - 22 * -exp(3)");
55+
writeln(result);
56+
} catch (CalcoolException ce) {
57+
// CalcoolException means your expression was not valid
58+
stderr.writefln(ce.msg);
59+
} catch (EndException e) {
60+
// Ignore EndException, it only indicates the end of parsing phase, sorry
61+
} catch (Exception e) {
62+
// Something bad happened! Do what you have to do.
63+
}
64+
2965
```
3066

3167
# License

source/app.d

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
module calcool.app;
12
version (CLI_APP) {
23
import std.stdio;
34
import std.getopt;

0 commit comments

Comments
 (0)