Skip to content

Instantly share code, notes, and snippets.

@rubenwardy
Last active July 12, 2018 13:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rubenwardy/f5676ebe451272941b2170d4cf264350 to your computer and use it in GitHub Desktop.
Save rubenwardy/f5676ebe451272941b2170d4cf264350 to your computer and use it in GitHub Desktop.
-- First check to see if it can be evaluated as an expression,
-- then fallback to executing it raw
local func, error = loadstring("return (" .. param .. ")")
if not func then
func, error = loadstring(param)
if not func then
return false, "E " .. error
end
end
local good, errOrResult = pcall(func)
if not good then
return false, "E " .. errOrResult
end
return true, "= " .. dump(errOrResult)
-- note: this function returns a tuple - (successBoolean,messageToSendToUser)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment