Skip to content
This repository has been archived by the owner on Dec 4, 2020. It is now read-only.

Commit

Permalink
Merge branch 'enhance-execution' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
zach2good committed Aug 29, 2020
2 parents 0f12d94 + 6470b92 commit b1fe7fc
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions scripts/commands/exec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,12 @@ function onTrigger(player, str)
local old_os = os
os = nil

-- Define "player" and "target" inside the string for use by the caller
local define_player = "local player = GetPlayerByName(\"" .. player:getName() .. "\"); "
local define_target = "local target = player:getCursorTarget(); "

-- Ensure the command compiles / is valid..
local scriptObj, err = loadstring(str)
local scriptObj, err = loadstring(define_player .. define_target .. str)
if (scriptObj == nil) then
player:PrintToPlayer("Failed to load the given string.")
player:PrintToPlayer(err)
Expand All @@ -37,7 +41,7 @@ function onTrigger(player, str)
-- Execute the string..
local status, err = pcall(scriptObj)
if (status == false) then
player:PrintToPlayer(err)
player:PrintToPlayer("Error calling: " .. str .. "\n" .. err)
end

-- Restore the os table..
Expand Down

0 comments on commit b1fe7fc

Please sign in to comment.