Adjust repl to allow dropping the parens around `?`
`?` with no arg also returns its own help text. Improve web help texts.
This commit is contained in:
parent
803935c637
commit
79a2d09995
15
src/env.c
15
src/env.c
|
@ -283,12 +283,16 @@ void printColored(const char* code)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn(help,
|
fn(help,
|
||||||
"Displays help text for the given function.\n"
|
"Gets a string with help text for the given function.\n"
|
||||||
"Currently requires the function name as a string, but future syntactic sugar may\n"
|
"For example:\n"
|
||||||
"loosen this requirement.\n"
|
" (? islist) => \"(islist (1 2 3)) => T\""
|
||||||
"(? \"+\") => \"(+ 1 2) => 3\""
|
|
||||||
) {
|
) {
|
||||||
const char* symbol = params[0].string;
|
const char* symbol;
|
||||||
|
if (!length || !params[0].string || params[0].string[0] == '\0') {
|
||||||
|
symbol = "?";
|
||||||
|
} else {
|
||||||
|
symbol = params[0].string;
|
||||||
|
}
|
||||||
for (int i = 0; i < currentHelp; i++) {
|
for (int i = 0; i < currentHelp; i++) {
|
||||||
struct helpText h = helpTexts[i];
|
struct helpText h = helpTexts[i];
|
||||||
if (strcmp(symbol, h.symbol) == 0) {
|
if (strcmp(symbol, h.symbol) == 0) {
|
||||||
|
@ -308,6 +312,7 @@ fn(help,
|
||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nullTerminated("Help not found!");
|
return nullTerminated("Help not found!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -606,6 +606,12 @@ void repl(struct Environment* env)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
add_history(buf);
|
add_history(buf);
|
||||||
|
if (buf[0] == '?' && (buf[1] == ' ' || buf[1] == '\0')) {
|
||||||
|
char* oldBuf = buf;
|
||||||
|
buf = malloc(sizeof(char) * strlen(buf + 3));
|
||||||
|
sprintf(buf, "(%s)", oldBuf);
|
||||||
|
free(oldBuf);
|
||||||
|
}
|
||||||
Object o = parseEval(buf, env);
|
Object o = parseEval(buf, env);
|
||||||
size_t length;
|
size_t length;
|
||||||
char *output = stringObj(&o, &length);
|
char *output = stringObj(&o, &length);
|
||||||
|
|
15
src/web.h
15
src/web.h
|
@ -9,16 +9,17 @@ fn(startServer,
|
||||||
);
|
);
|
||||||
|
|
||||||
fn(addGetRoute,
|
fn(addGetRoute,
|
||||||
"Note: Implementation bugs currently prevent using an inline lambda.\n"
|
"Adds a GET route at the given path with the given function.\n"
|
||||||
" (def homepage (fn () (\"Hello, world!\")))\n"
|
" (get \"/\" (fn () (\"Hello, world!\")))\n"
|
||||||
" (get \"/\" homepage)\n"
|
" (get \"/parampath\" (fn (req) (req's queryParams)))\n"
|
||||||
" (def queryPage (fn (req) (req's queryParams)))\n"
|
|
||||||
" (get \"/x\" queryPage)\n"
|
|
||||||
" (serve)\n"
|
" (serve)\n"
|
||||||
|
"Also see: (serve)\n"
|
||||||
);
|
);
|
||||||
|
|
||||||
fn(addPostRoute,
|
fn(addPostRoute,
|
||||||
"Note: Implementation bugs currently prevent using an inline lambda.\n"
|
"Adds a POST route at the given path with the given function.\n"
|
||||||
" (def homepage (fn () (\"Hello, world!\")));(post \"/\" homepage)\n"
|
"Note: Can't do anything with POSTed data yet.\n"
|
||||||
|
" (post \"/\" (fn () (\"Hello, world!\")))\n"
|
||||||
" (serve)\n"
|
" (serve)\n"
|
||||||
|
"Also see: (serve)\n"
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in New Issue