Add a simple lua console to allow evaluation of conde into init.lua

svn path=/trunk/; revision=19332
This commit is contained in:
Luis Ontanon 2006-09-27 02:51:08 +00:00
parent 354983d30d
commit 611d1e6443
1 changed files with 25 additions and 0 deletions

View File

@ -51,6 +51,31 @@ end
-- have print() call info() instead.
print = info
-- a Console to execute commands in lua
function wslua_console()
local w = TextWindow.new("Lua Console")
w:set_editable(TRUE)
function eval()
local text = string.gsub(w:get_text(),"%c*--%[%[.*--%]%]$","")
text = string.gsub(text,"^=","return ")
local result = assert(loadstring(text))()
if (result ~= nil) then
w:set(text .. '\n\n--[[ Result:\n' .. result .. '\n--]]')
else
w:set(text .. '\n\n--[[ Evaluated --]]')
end
end
w:add_button("Evaluate",eval)
end
register_menu("Lua Console",wslua_console)
-- %WTAP_ENCAPS%
-- %FT_TYPES%