Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Original by http://www.computercraft.info/forums2/index.php?/user/10136-engineer/
- local args = { ... }
- if fs.exists( args[1] ) then
- local f = fs.open( args[1], "r" )
- local content = f.readAll()
- f.close()
- local func, err = loadstring( content, args[1] )
- if not func then error( "Cannot propely sandbox this file: ".. err, 0 ) end
- local tArgs = {}
- for k, v in pairs( args ) do
- if k ~= 1 then
- tArgs[#tArgs + 1] = v
- end
- end
- setfenv( func, setmetatable( {}, { __index = _G; __newindex = function( t, k, v ) printError( "Program is accessing global variables.", 0 ) end } ))
- func( unpack(tArgs) )
- else
- printError( "Cannot sandbox a non-existing file!", 0 )
- end
Add Comment
Please, Sign In to add comment