From 9a4c796d20428c88d5bbb20b412afd740fadac2f Mon Sep 17 00:00:00 2001 From: mitchell <70453897+667e-11@users.noreply.github.com> Date: Mon, 20 May 2013 19:12:15 -0400 Subject: Print the results of '=' Lua expressions; modules/textadept/command_entry.lua --- modules/textadept/command_entry.lua | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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') -- cgit v1.2.3