Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
bobimicroweber committed Aug 17, 2024
1 parent 768dec7 commit 8f3f436
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 10 deletions.
15 changes: 10 additions & 5 deletions davi.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,22 @@ func main() {
//$url = "https://api.open-meteo.com/v1/forecast?latitude=52.52&longitude=13.41&current=temperature_2m,wind_speed_10m&hourly=temperature_2m,relative_humidity_2m,wind_speed_10m";
//fileGetContents($url);
function jsonHandler() {
$timeHandler = function() {
$time = time();
return($time);
}
//httpRegister("/", "Cool!");
//httpRegister("/hello", "Hello, World!");
//httpRegister("/json", "Json!");
//httpListen(":3030");
$time = time();
echo($time);
httpRegister("/time", $timeHandler);
httpListen(":3030");
lst = ["foo", "a", "z", "B"]
sort(lst, lower);
for x in lst {
echo(x);
}
`)

Expand Down
13 changes: 9 additions & 4 deletions interpreter/functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -497,20 +497,25 @@ func fileGetContentsFunction(interp *interpreter, pos Position, args []Value) Va
func httpRegisterFunction(interp *interpreter, pos Position, args []Value) Value {

ensureNumArgs(pos, "httpRegister", args, 2)

//
if len(args) != 1 && len(args) != 2 {
panic(typeError(pos, "httpRegisterFunction() requires 2 args, got %d", len(args)))
}

handlerFunction, ok := args[1].(functionType)
if !ok {
panic(typeError(pos, "httpRegisterFunction() requires second argument to be a function"))
}

formatter := prettyjson.NewFormatter()
output, _ := formatter.Marshal(args)
output, _ := formatter.Marshal(handlerFunction)
fmt.Println(string(output))

pattern := args[0].(string)
handler := args[1].(string)

getRoot := func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintln(w, handler)
outputFunction := interp.callFunction(pos, handlerFunction, []Value{})
fmt.Fprintln(w, outputFunction)
}
http.HandleFunc(pattern, getRoot)

Expand Down
7 changes: 6 additions & 1 deletion parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,12 @@ func (p *parser) call() Expression {
p.error("can only have ... after last argument")
}
p.expect(RPAREN)
p.expect(SEMI)
if p.tok == SEMI {
p.expect(SEMI)
} else {
print(p.tok)
}

expr = &Call{pos, expr, args, gotEllipsis}
} else if p.tok == LBRACKET {
pos := p.pos
Expand Down

0 comments on commit 8f3f436

Please sign in to comment.