Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function os.pullEventRaw( sFilter )
- return coroutine.yield( sFilter )
- end
- function os.pullEvent( sFilter )
- local eventData = table.pack( os.pullEventRaw( sFilter ) )
- if eventData[1] == "terminate" then
- error( "Terminated", 0 )
- end
- return table.unpack( eventData, 1, eventData.n )
- end
- -- Install globals
- function sleep( nTime )
- if nTime ~= nil and type( nTime ) ~= "number" then
- error( "bad argument #1 (expected number, got " .. type( nTime ) .. ")", 2 )
- end
- local timer = os.startTimer( nTime or 0 )
- repeat
- local sEvent, param = os.pullEvent( "timer" )
- until param == timer
- end
- local tAPIsLoading = {}
- function os.loadAPI( _sPath )
- if type( _sPath ) ~= "string" then
- error( "bad argument #1 (expected string, got " .. type( _sPath ) .. ")", 2 )
- end
- local sName = fs.getName( _sPath )
- if sName:sub(-4) == ".lua" then
- sName = sName:sub(1,-5)
- end
- if tAPIsLoading[sName] == true then
- printError( "API "..sName.." is already being loaded" )
- return false
- end
- tAPIsLoading[sName] = true
- local tEnv = {}
- setmetatable( tEnv, { __index = _G } )
- local fnAPI, err = loadfile( _sPath, tEnv )
- if fnAPI then
- local ok, err = pcall( fnAPI )
- if not ok then
- printError( err )
- tAPIsLoading[sName] = nil
- return false
- end
- else
- printError( err )
- tAPIsLoading[sName] = nil
- return false
- end
- local tAPI = {}
- for k,v in pairs( tEnv ) do
- if k ~= "_ENV" then
- tAPI[k] = v
- end
- end
- _G[sName] = tAPI
- tAPIsLoading[sName] = nil
- return true
- end
- os.loadAPI("/rom/textutils")
- os.loadAPI("/rom/peripheral")
- loadfile = function( _sFile, _tEnv )
- if type( _sFile ) ~= "string" then
- error( "bad argument #1 (expected string, got " .. type( _sFile ) .. ")", 2 )
- end
- if _tEnv ~= nil and type( _tEnv ) ~= "table" then
- error( "bad argument #2 (expected table, got " .. type( _tEnv ) .. ")", 2 )
- end
- local file = fs.open( _sFile, "r" )
- if file then
- local func, err = loadstring( file.readAll(), fs.getName( _sFile ), "t", _tEnv )
- file.close()
- return func, err
- end
- return nil, "File not found"
- end
- dofile = function( _sFile )
- if type( _sFile ) ~= "string" then
- error( "bad argument #1 (expected string, got " .. type( _sFile ) .. ")", 2 )
- end
- local fnFile, e = loadfile( _sFile, _G )
- if fnFile then
- return fnFile()
- else
- error( e, 2 )
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment