Alex Roitman b55300b729 Lua scripting feature. (#224)
* Start on lua scripting

* Implement evalsha, script load, script exists, and script flush

* Type conversions from lua to resp/json.
Refactor to make luastate and luascripts persistent in the controller.

* Change controller.command and all underlying commands to return resp.Value.
Serialize only during the ouput.

* First stab at tile38 call from lua

* Change tile38 into tile38.call in Lua

* Property return errors from scripts

* Minor refactoring.  No locking on script run

* Cleanup/refactoring

* Create a pool of 5 lua states, allow for more as needed. Refactor.

* Use safe map for scripts.  Add a limit for max number of lua states.  Refactor.

* Refactor

* Refactor script commands into atomic, read-only, and non-atomic classes.
Proper locking for all three classes.
Add tests for scripts

* More tests for scripts

* Properly escape newlines in lua-produced errors

* Better test for readonly failure

* Correctly convert ok/err messages between lua and resp.
Add pcall, sha1hex, error_reply, status_reply functions to tile38 namespace in lua.

* Add pcall test. Change writeErr to work with string argument

* Make sure eval/evalsha never attempt to write AOF

* Add eval-set and eval-get to benchmarks

* Fix eval benchmark tests, add more

* Improve benchmarks

* Optimizations and refactoring.

* Add lua memtest

* Typo

* Add dependency

* golint fixes

* gofmt fixes

* Add scripting commands to the core/commands.json

* Use ARGV for args inside lua
2017-10-05 08:20:40 -07:00

87 lines
2.1 KiB
Lua

-- debug lib tests
-- debug stuff are partially implemented; hooks are not supported.
local function f1()
end
local env = {}
local mt = {}
debug.setfenv(f1, env)
assert(debug.getfenv(f1) == env)
debug.setmetatable(f1, mt)
assert(debug.getmetatable(f1) == mt)
local function f2()
local info = debug.getinfo(1, "Slunf")
assert(info.currentline == 14)
assert(info.linedefined == 13)
assert(info.func == f2)
assert(info.lastlinedefined == 25)
assert(info.nups == 1)
assert(info.name == "f2")
assert(info.what == "Lua")
if string.find(_VERSION, "GopherLua") then
assert(info.source == "db.lua")
end
end
f2()
local function f3()
end
local info = debug.getinfo(f3)
assert(info.currentline == -1)
assert(info.linedefined == 28)
assert(info.func == f3)
assert(info.lastlinedefined == 29)
assert(info.nups == 0)
assert(info.name == nil)
assert(info.what == "Lua")
if string.find(_VERSION, "GopherLua") then
assert(info.source == "db.lua")
end
local function f4()
local a,b,c = 1,2,3
local function f5()
local name, value = debug.getlocal(2, 2)
assert(debug.getlocal(2, 10) == nil)
assert(name == "b")
assert(value == 2)
name = debug.setlocal(2, 2, 10)
assert(debug.setlocal(2, 10, 10) == nil)
assert(name == "b")
local d = a
local e = c
local tb = debug.traceback("--msg--")
assert(string.find(tb, "\\-\\-msg\\-\\-"))
assert(string.find(tb, "in.*f5"))
assert(string.find(tb, "in.*f4"))
end
f5()
local name, value = debug.getupvalue(f5, 1)
assert(debug.getupvalue(f5, 10) == nil)
assert(name == "a")
assert(value == 1)
name = debug.setupvalue(f5, 1, 11)
assert(debug.setupvalue(f5, 10, 11) == nil)
assert(name == "a")
assert(a == 11)
assert(b == 10) -- changed by debug.setlocal in f4
end
f4()
local ok, msg = pcall(function()
debug.getlocal(10, 1)
end)
assert(not ok and string.find(msg, "level out of range"))
local ok, msg = pcall(function()
debug.setlocal(10, 1, 1)
end)
assert(not ok and string.find(msg, "level out of range"))
assert(debug.getinfo(100) == nil)
assert(debug.getinfo(1, "a") == nil)