[code] [textadept] Printing result of lua evaluation

From: Chris Emerson <c-ta.att.mail.nosreme.org>
Date: Mon, 20 May 2013 20:44:01 +0100

Hi,

I find it convenient to be able to print the result of expressions in the
command_entry/lua_command box.

Would you consider the following change, which (a) adds support for prefixing
an expression with "=" to print the result, like in the default Lua shell,
and (b) gui.print() any non-nil result?

diff -r 355b6b7dd1aa modules/textadept/command_entry.lua
--- a/modules/textadept/command_entry.lua Mon May 20 20:34:26 2013 +0100
+++ b/modules/textadept/command_entry.lua Mon May 20 20:34:35 2013 +0100
@@ -102,9 +102,15 @@
 -- @param code The Lua code to execute.
 -- @name execute_lua
 function M.execute_lua(code)
+ if string.sub(code, 1, 1) == "=" then
+ code = "return " .. string.sub(code, 2)
+ end
   local f, err = load(code, nil, 'bt', env)
   if err then error(err) end
- f()
+ result = f()
+ if result ~= nil then
+ gui.print("Result:", result)
+ end
   events.emit(events.UPDATE_UI)
 end
 args.register('-e', '--execute', 1, M.execute_lua, 'Execute Lua code')

Regards,

Chris

-- 
You are subscribed to code.att.foicica.com.
To change subscription settings, send an e-mail to code+help.att.foicica.com.
To unsubscribe, send an e-mail to code+unsubscribe.att.foicica.com.
Received on Mon 20 May 2013 - 15:44:01 EDT

This archive was generated by hypermail 2.2.0 : Tue 21 May 2013 - 06:42:34 EDT