landsandboat/scripts/commands/exec.lua
MrHappyAsthma 36fdb3ea7e Bulk remove semicolons from Lua scripts/commands.
This may not actually be every file, but I did the best I could.

Command applied:
    find . -type f -name "*.lua" | xargs -d '\n' sed -i 's/;//g'

Semicolons are not appropriate in Lua per the style guidelines:
    https://github.com/project-topaz/topaz/blob/master/CONTRIBUTING.md
2020-02-19 21:42:47 -08:00

45 lines
No EOL
1.2 KiB
Lua

---------------------------------------------------------------------------------------------------
-- func: exec
-- desc: Allows you to execute a Lua string directly from chat.
---------------------------------------------------------------------------------------------------
cmdprops =
{
permission = 4,
parameters = "s"
}
function error(player, msg)
player:PrintToPlayer(msg)
player:PrintToPlayer("!exec <Lua string>")
end
function onTrigger(player, str)
-- Ensure a command was given..
if (str == nil or string.len(str) == 0) then
error(player, "You must enter a string to execute.")
return
end
-- For safety measures we will nuke the os table..
local old_os = os
os = nil
-- Ensure the command compiles / is valid..
local scriptObj, err = loadstring(str)
if (scriptObj == nil) then
player:PrintToPlayer("Failed to load the given string.")
player:PrintToPlayer(err)
os = old_os
return
end
-- Execute the string..
local status, err = pcall(scriptObj)
if (status == false) then
player:PrintToPlayer(err)
end
-- Restore the os table..
os = old_os
end