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 4c91090 commit 818a7dd
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
7 changes: 7 additions & 0 deletions davi.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,16 @@ 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() {
$time = time();
return($time);
}
$json = jsonHandler();
httpRegister("/", "Cool!");
httpRegister("/hello", "Hello, World!");
httpRegister("/json", $json);
httpListen(":3030");
`)
Expand Down
9 changes: 9 additions & 0 deletions examples/ClosureFunctionInVariable.davi
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?davi


$jsonHandler = function() {
echo("Hello, World!");
}
$jsonHandler();

?>
10 changes: 10 additions & 0 deletions interpreter/functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"sort"
"strconv"
"strings"
"time"
)

type functionType interface {
Expand Down Expand Up @@ -97,6 +98,7 @@ var builtins = map[string]builtinFunction{
"str": {strFunction, "str"},
"type": {typeFunction, "type"},
"upper": {upperFunction, "upper"},
"time": {timeFunction, "time"},
"fileGetContents": {fileGetContentsFunction, "fileGetContents"},
"httpRegister": {httpRegisterFunction, "httpRegister"},
"httpListen": {httpListenFunction, "httpListen"},
Expand Down Expand Up @@ -460,6 +462,14 @@ func upperFunction(interp *interpreter, pos Position, args []Value) Value {
panic(typeError(pos, "upper() requires a str"))
}

func timeFunction(interp *interpreter, pos Position, args []Value) Value {
ensureNumArgs(pos, "time", args, 0)

dt := time.Now()

return Value(dt.String())
}

func fileGetContentsFunction(interp *interpreter, pos Position, args []Value) Value {

ensureNumArgs(pos, "fileGetContents", args, 1)
Expand Down

0 comments on commit 818a7dd

Please sign in to comment.