-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[patch] Merge pull request #1 from feature/add-lua-scripting-feature
- Loading branch information
Showing
14 changed files
with
302 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
-- dump.lua is useful for debugging. | ||
-- `results` is a slice of search results. | ||
|
||
for i, r in results() do | ||
print(string.format("Id: %s, Distance: %3.7f", r.Id, r.Distance)) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
-- `results` is a slice of search results. | ||
|
||
-- using vadv/gopher-lua-libs | ||
local json = require("json") | ||
local time = require("time") | ||
|
||
for i, r in results() do | ||
results[i].Id = json.encode( | ||
{ | ||
id = r.Id, | ||
time = time.format(time.unix(), "Jan 2 15:04:05 2006", "Asia/Tokyo") | ||
} | ||
) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
-- `results` is a slice of search results. | ||
|
||
local remains = {} | ||
for i, r in results() do | ||
-- remove elements by distances | ||
if r.Distance < 10.9 then | ||
remains[#remains+1] = r | ||
end | ||
|
||
results[i] = nil | ||
end | ||
|
||
for i, r in pairs(remains) do | ||
results[i] = r | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
-- `results` is a slice of search results. | ||
|
||
for i, r in results() do | ||
results[i].Id = string.reverse(r.Id) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
-- `results` is a slice of search results. | ||
-- to apply `table.sort`, put the data into `sorter` | ||
|
||
local sorter = {} | ||
for i, r in results() do | ||
sorter[i] = r | ||
end | ||
|
||
-- sort | ||
table.sort(sorter, function(a, b) | ||
-- reverse order | ||
return a.Distance > b.Distance | ||
end) | ||
|
||
-- put the sorted data into `results` | ||
for i, r in pairs(sorter) do | ||
results[i] = r | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.