Merge branch 'lua/distance_to' of https://github.com/rshura/tile38 into rshura-lua/distance_to

This commit is contained in:
tidwall 2019-01-06 10:29:59 -07:00
commit ed31f2bd4c
2 changed files with 13 additions and 0 deletions

View File

@ -13,6 +13,7 @@ import (
"sync"
"time"
"github.com/tidwall/geojson/geo"
"github.com/tidwall/resp"
"github.com/tidwall/tile38/internal/log"
"github.com/yuin/gopher-lua"
@ -142,12 +143,22 @@ func (pl *lStatePool) New() *lua.LState {
ls.Push(lua.LString(shaSum))
return 1
}
distanceTo := func(ls *lua.LState) int {
dt := geo.DistanceTo(
float64(ls.ToNumber(1)),
float64(ls.ToNumber(2)),
float64(ls.ToNumber(3)),
float64(ls.ToNumber(4)))
ls.Push(lua.LNumber(dt))
return 1
}
var exports = map[string]lua.LGFunction{
"call": call,
"pcall": pcall,
"error_reply": errorReply,
"status_reply": statusReply,
"sha1hex": sha1hex,
"distance_to": distanceTo,
}
L.SetGlobal("tile38", L.SetFuncs(L.NewTable(), exports))

View File

@ -24,6 +24,8 @@ func scripts_BASIC_test(mc *mockServer) error {
{"EVAL", "return KEYS[1] .. ' only'", 1, "key1"}, {"key1 only"},
{"EVAL", "return KEYS[1] .. ' and ' .. ARGV[1]", 1, "key1", "arg1"}, {"key1 and arg1"},
{"EVAL", "return ARGV[1] .. ' and ' .. ARGV[2]", 0, "arg1", "arg2"}, {"arg1 and arg2"},
{"EVAL", "return tile38.sha1hex('asdf')", 0}, {"3da541559918a808c2402bba5012f6c60b27661c"},
{"EVAL", "return tile38.distance_to(37.7341129, -122.4408378, 37.733, -122.43)", 0}, {"961"},
})
}