aboutsummaryrefslogtreecommitdiff
path: root/modules/textadept/command_entry.lua
diff options
context:
space:
mode:
authormitchell <70453897+667e-11@users.noreply.github.com>2020-03-03 19:39:02 -0500
committermitchell <70453897+667e-11@users.noreply.github.com>2020-03-03 19:39:02 -0500
commitfceb1a37df623649d191c3c1a881e5b0538b1391 (patch)
tree87a34dfc2397dc4afdaa0c8ec189f037300f458e /modules/textadept/command_entry.lua
parent1618f5017abb3c9bacc9ba346bf22a936ef5dd06 (diff)
downloadtextadept-fceb1a37df623649d191c3c1a881e5b0538b1391.tar.gz
textadept-fceb1a37df623649d191c3c1a881e5b0538b1391.zip
Added test suite and API type checking for more helpful error messages.
Diffstat (limited to 'modules/textadept/command_entry.lua')
-rw-r--r--modules/textadept/command_entry.lua27
1 files changed, 14 insertions, 13 deletions
diff --git a/modules/textadept/command_entry.lua b/modules/textadept/command_entry.lua
index b652e9d9..a668516f 100644
--- a/modules/textadept/command_entry.lua
+++ b/modules/textadept/command_entry.lua
@@ -44,20 +44,18 @@ M.editing_keys = {__index = {
-- @name env
local env = setmetatable({}, {
__index = function(_, k)
- local f = buffer[k]
- if f and type(f) == 'function' then
- f = function(...) return buffer[k](buffer, ...) end
- elseif f == nil and type(view[k]) == 'function' then
- f = function(...) view[k](view, ...) end -- do not return a value
- elseif f == nil then
- f = view[k] or ui[k] or _G[k]
+ if type(buffer[k]) == 'function' then
+ return function(...) return buffer[k](buffer, ...) end
+ elseif type(view[k]) == 'function' then
+ return function(...) view[k](view, ...) end -- do not return a value
end
- return f
+ return buffer[k] or view[k] or ui[k] or _G[k]
end,
__newindex = function(self, k, v)
local ok, value = pcall(function() return buffer[k] end)
if ok and value ~= nil or not ok and value:find('write-only property') then
- buffer[k] = v return
+ buffer[k] = v
+ return
end
if view[k] ~= nil then view[k] = v return end
if ui[k] ~= nil then ui[k] = v return end
@@ -165,12 +163,15 @@ local lua_mode_keys = {['\t'] = complete_lua}
-- @name run
function M.run(f, mode_keys, lexer, height)
if M:auto_c_active() then M:auto_c_cancel() end -- may happen in curses
- if not f and not mode_keys then
+ if not assert_type(f, 'function/nil', 1) and not mode_keys then
f, mode_keys, lexer = run_lua, lua_mode_keys, 'lua'
- elseif type(mode_keys) == 'string' then
- mode_keys, lexer, height = {}, mode_keys, lexer
- elseif not mode_keys then
+ elseif type(assert_type(mode_keys, 'table/string/nil', 2)) == 'string' then
+ lexer, height = mode_keys, assert_type(lexer, 'number/nil', 3)
mode_keys = {}
+ else
+ if not mode_keys then mode_keys = {} end
+ assert_type(lexer, 'string/nil', 3)
+ assert_type(height, 'number/nil', 4)
end
if not mode_keys['esc'] then mode_keys['esc'] = M.focus end -- hide
mode_keys['\n'] = mode_keys['\n'] or function()