But if its possible wihtout JLua then how? I tried and failed. I looked at the shell script in CC but I dont get it at all. Well I just need an answer if this was done in JLua, if not I need an explanation how.
Thanks in advance,
LeDark Lua.
shell.run(FilePath+FileName, arg1, arg2, arg3, ..., argN)
local superAwesomeAPI = {
-- Super awesome stuff goes here.
}
--[[
Loads a file at a given path as a function and executes it with
the given arguments. Once the function is loaded, it is given an
environment which has access to the _G table via __index, as well
as our super special API table.
@param path -- The path of the file to be loaded and executed.
@param ... -- The arguments to pass to the loaded program.
]]
function run(path, ...)
-- Uses the fs API from CC. You could just use the io API from native Lua if not operating
-- within CC.
local fileHandle = fs.open(path, 'r')
-- Make sure the file was opened properly.
if not fileHandle then
return false
end
local program = loadstring(fileHandle.readAll())
-- Program was not valid Lua (was not interpreted properly).
if not program then
return false
end
local environment = setmetatable({ superAwesomeAPI = superAwesomeAPI }, { __index = _G })
program = setfenv(program, environment)
if not program then
return false
end
return pcall(program, ...)
end
--#pseudo code
--#a recreation of shell.run
args = {}
filepath, args = ...
--#load the file
loadedFile = loadfile(filepath)
--#run the loaded file
loadedFile(unpack(args))