diff options
author | 2013-05-20 19:12:15 -0400 | |
---|---|---|
committer | 2013-05-20 19:12:15 -0400 | |
commit | 9a4c796d20428c88d5bbb20b412afd740fadac2f (patch) | |
tree | 6627947ff84bcca2b4871b310e90eab0e27de207 | |
parent | f13108c187a893db2a66de970cbb44e40ac518ce (diff) | |
download | textadept-9a4c796d20428c88d5bbb20b412afd740fadac2f.tar.gz textadept-9a4c796d20428c88d5bbb20b412afd740fadac2f.zip |
Print the results of '=' Lua expressions; modules/textadept/command_entry.lua
-rw-r--r-- | modules/textadept/command_entry.lua | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/modules/textadept/command_entry.lua b/modules/textadept/command_entry.lua index a22b10c6..dab02e2b 100644 --- a/modules/textadept/command_entry.lua +++ b/modules/textadept/command_entry.lua @@ -99,12 +99,15 @@ local env = setmetatable({}, { -- Executes string *code* as Lua code. -- Code is subject to an "abbreviated" environment where the `buffer`, `view`, -- and `gui` tables are also considered as globals. +-- Print the results of '=' expressions like in the Lua prompt. -- @param code The Lua code to execute. -- @name execute_lua function M.execute_lua(code) + if code:sub(1, 1) == '=' then code = 'return '..code:sub(2) end local f, err = load(code, nil, 'bt', env) if err then error(err) end - f() + local result = f() + if result ~= nil then gui.print(result) end events.emit(events.UPDATE_UI) end args.register('-e', '--execute', 1, M.execute_lua, 'Execute Lua code') |