Add basic (time) function and Time struct.
Also add pebblisp.pbl config file to examples/
This commit is contained in:
parent
75ba0ac5ee
commit
342eba3a0d
|
@ -414,9 +414,6 @@ struct Environment defaultEnv()
|
|||
pf(at),
|
||||
pf(rest),
|
||||
pf(charAt),
|
||||
#ifndef LOW_MEM
|
||||
pf(reverse),
|
||||
#endif
|
||||
pf(isNum),
|
||||
pf(isList),
|
||||
pf(isString),
|
||||
|
@ -424,6 +421,10 @@ struct Environment defaultEnv()
|
|||
pf(charVal),
|
||||
pf(parseEvalO),
|
||||
pf(possessive),
|
||||
pf(getTime),
|
||||
#ifndef LOW_MEM
|
||||
pf(reverse),
|
||||
#endif
|
||||
#ifdef WEBSERVER
|
||||
pf(addGetRoute),
|
||||
pf(addPostRoute),
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
(def red "[31m")
|
||||
(def green "[32m")
|
||||
(def blue "[34m")
|
||||
(def bold "[1m")
|
||||
(def reset "[0m")
|
||||
(def nl (ch 10))
|
||||
|
||||
(def hour (fn (ti) (
|
||||
(def h (% ti's hour 12))
|
||||
(if (= 0 h) 12 h)
|
||||
)))
|
||||
|
||||
(def zero (fn (num) (cat (if (< num 10) "0" "") num)))
|
||||
|
||||
(def clock (fn (ti) (cat (hour ti) ":" (zero ti's minute) ":" (zero ti's sec))))
|
||||
|
||||
(def prompt (fn (a) (
|
||||
(sys "echo")
|
||||
(def ti (time))
|
||||
|
||||
(def m ti's minute)
|
||||
(def s ti's sec)
|
||||
|
||||
(cat red bold "[sage] " blue (clock) nl green bold "pebblisp ~> " reset)
|
||||
)))
|
18
src/plfunc.c
18
src/plfunc.c
|
@ -486,4 +486,22 @@ Object readFileToObject(Object* params, int length, struct Environment* env)
|
|||
return string;
|
||||
}
|
||||
|
||||
#include <time.h>
|
||||
|
||||
int timeStructDefinition = -1;
|
||||
Object getTime(Object* params, int length, struct Environment* env)
|
||||
{
|
||||
if (timeStructDefinition == -1) {
|
||||
parseEval("(struct Time (minute hour sec))", env);
|
||||
}
|
||||
timeStructDefinition = getStructIndex("Time");
|
||||
time_t t = time(NULL);
|
||||
struct tm tm = *localtime(&t);
|
||||
Object o = structObject(timeStructDefinition);
|
||||
o.structObject->fields[0] = numberObject(tm.tm_min);
|
||||
o.structObject->fields[1] = numberObject(tm.tm_hour);
|
||||
o.structObject->fields[2] = numberObject(tm.tm_sec);
|
||||
return o;
|
||||
}
|
||||
|
||||
#endif // STANDALONE
|
||||
|
|
|
@ -240,6 +240,10 @@ tfn(readFileToObject, "rf",
|
|||
"Read a file into a string object."
|
||||
);
|
||||
|
||||
fn(getTime, "time",
|
||||
"Get a struct of the current time with fields (minute hour sec)."
|
||||
);
|
||||
|
||||
#endif // STANDALONE
|
||||
|
||||
#endif // PEBBLISP_PLFUNC_H
|
Loading…
Reference in New Issue