Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local tAPIsLoading = {}
- function os.loadAPI( _sPath )
- local sName = fs.getName( _sPath )
- 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 )
- if fnAPI then
- setfenv( fnAPI, tEnv )
- local bSuccess, err = pcall( fnAPI )
- if not bSuccess 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
- tAPI[k] = v
- end
- _G[sName] = tAPI
- tAPIsLoading[sName] = nil
- return true
- end
Advertisement
Add Comment
Please, Sign In to add comment