Posted 17 July 2017 - 04:09 AM
I have a function I like to call "require" because CC misses the require ability.
require.lua
But the module I try require is not run virtually inside the function it still have access to everything thats going around, as well as the Global variable defined in the start of the file. So I wonder how I can run the file virtually without having to start a new shell. So how do I run the code in a sandbox mode?
require.lua
if Global == nil then Global = {}; end
function require (mod, useExtenstion)
__exports__, __name__ = nil, nil;
local cDir = getDir();
local path = cDir .. '/' .. mod;
if useExtenstion ~= nil or not useExtenstion then path = path .. '.lua'; end
if not fs.exists(path) then return false; end
local fileHandle = fs.open(path, 'r');
local mods = fileHandle.readAll();
fileHandle.close();
module = {};
loadstring(mods)();
if
__name__ == nil or
type(__name__) ~= 'string' or
__exports__ == nil
then
print('module [' .. mod .. '] does not use module.* correctly');
sleep(3);
os.shutdown();
end
Global[__name__] = __exports__;
Global['callid:' .. mod .. '/script'] = __name__;
__exports__, __name__ = nil, nil;
return Global[Global['callid:' .. mod .. '/script']];
end
But the module I try require is not run virtually inside the function it still have access to everything thats going around, as well as the Global variable defined in the start of the file. So I wonder how I can run the file virtually without having to start a new shell. So how do I run the code in a sandbox mode?