Error and return echoing lua execute alias

Share your scripts and packages with other Mudlet users.
Post Reply
Sanaki
Posts: 110
Joined: Wed Mar 09, 2011 1:30 am

Error and return echoing lua execute alias

Post by Sanaki »

Below is my Lua execution alias for Mudlet with both compile and runtime error echoing. Feel free to use and distribute as needed, just give credit where credit is due. Also, note that this will error on something like "luar 5". It's script execution, not evaluation. You'll need to use "luar return 5" if that's what you want.

SYNTAX:
LUA <code> - Runs the code given
LUAR <code> - Runs the code given and displays all return values, if any

Alias pattern:
Code: [show] | [select all] lua
^luar? (.+)$
Script:
Code: [show] | [select all] lua
local f,e,eh,r
f,e = loadstring(matches[2])
eh = function(err) echo("\nError in code execution:\n"..err) end
r = {xpcall(f,eh)}
if not r[1] and e then
	echo("\nLua code compile error:\n"..e)
else
	if matches[1]:sub(4,4) == "r" then
		table.remove(r,1)
		if #r>0 then
			display(setmetatable(r, {__index={__customtype="Return Values"}}))
		else
			echo("\nNo return values for given code.")
		end
	end
end

EDIT: Forgot to include the xml for ease of import. Here you go:
luaexe.xml
Lua Execution alias
(876 Bytes) Downloaded 474 times

Post Reply