mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2025-12-28 03:55:23 +09:00
Added module: ExpGamingCore.Commands
This commit is contained in:
@@ -193,7 +193,10 @@ end
|
||||
-- @tparam[opt] ?Server._thread|true use_thread run the command on a premade thread or let it make its own
|
||||
-- @tparam[opt] table env run the env to run the command in must have _env key as true to be
|
||||
-- @param[opt] ... any args you want to pass to the function
|
||||
-- @return if no thread then it will return the value(s) returned by the callback
|
||||
-- @treturn[1] boolean if no thread then it will return a true for the success
|
||||
-- @return[1] if no thread then it will return the value(s) returned by the callback
|
||||
-- @treturn[2] boolean if no thread then it will return a false for the success
|
||||
-- @treturn[2] string if no thread then it will return a an err value
|
||||
function Server.interface(callback,use_thread,env,...)
|
||||
if use_thread then
|
||||
-- if use_thread is true then it makes a new thread
|
||||
@@ -217,15 +220,20 @@ function Server.interface(callback,use_thread,env,...)
|
||||
use_thread:open()
|
||||
Server.queue_thread(use_thread)
|
||||
else
|
||||
local callback = is_type(callback,'function') and callback or loadstring(callback)
|
||||
local _callback = callback
|
||||
if not is_type(callback,'function') then
|
||||
local rtn, err = loadstring(callback)
|
||||
if err then return false, err end
|
||||
_callback = rtn
|
||||
end
|
||||
if is_type(env,'table') and env._env == true then
|
||||
local sandbox, success, err = Manager.sandbox(callback,env,unpack(thread.data))
|
||||
if not success then error(err) end
|
||||
return err
|
||||
local sandbox, success, err = Manager.sandbox(_callback,env,...)
|
||||
if not success then error(err) return success,err
|
||||
else return success, unpack(err) end
|
||||
else
|
||||
local sandbox, success, err = Manager.sandbox(callback,{},env,unpack(thread.data))
|
||||
if not success then error(err) end
|
||||
return err
|
||||
local sandbox, success, err = Manager.sandbox(_callback,{},env,...)
|
||||
if not success then error(err) return success,err
|
||||
else return success, unpack(err) end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -10,7 +10,9 @@
|
||||
--- Runs the given input from the script
|
||||
-- @command interface
|
||||
-- @param code The code that will be ran
|
||||
commands.add_command('interface', 'Runs the given input from the script', {'code',true}, function(event,args)
|
||||
commands.add_command('interface',{'Server.interface-description'}, {
|
||||
['code']={true,'string-inf'}
|
||||
}, function(event,args)
|
||||
local callback = args.code
|
||||
-- looks for spaces, if non the it will prefix the command with return
|
||||
if not string.find(callback,'%s') and not string.find(callback,'return') then callback = 'return '..callback end
|
||||
@@ -28,7 +30,7 @@ commands.add_command('interface', 'Runs the given input from the script', {'code
|
||||
-- runs the function
|
||||
local success, err = Server.interface(callback,false,env)
|
||||
-- if there is an error then it will remove the stacktrace and return the error
|
||||
if not success and is_type(err,'string') then local _end = string.find(err,'stack traceback') if _end then err = string.sub(err,0,_end-2) end end
|
||||
if not success and is_type(err,'string') then local _end = string.find(err,':1:') if _end then err = string.sub(err,_end+4) end end
|
||||
-- if there is a value returned that is not nill then it will return that value
|
||||
if err or err == false then player_return(err) end
|
||||
end)
|
||||
Reference in New Issue
Block a user