Advertisement
billysback

loading classes

Jun 26th, 2013
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.64 KB | None | 0 0
  1. local tAPIsLoading = {}
  2. function newClass(path)
  3.     local _sPath = path
  4.     local sName = fs.getName( _sPath )
  5.     local n = 1
  6.     while tAPIsLoading[sName] == true and n < 300 do
  7.         n = n + 1
  8.         sleep(0)
  9.     end
  10.     if n < 300 then
  11.         tAPIsLoading[sName] = true
  12.            
  13.         local tEnv = {}
  14.         setmetatable( tEnv, { __index = _G } )
  15.         local fnAPI, err = loadfile( _sPath )
  16.         if fnAPI then
  17.             setfenv( fnAPI, tEnv )
  18.             fnAPI()
  19.         else
  20.             printError( err )
  21.             tAPIsLoading[sName] = nil
  22.             return nil
  23.         end
  24.        
  25.         local tAPI = {}
  26.         for k,v in pairs( tEnv ) do
  27.             tAPI[k] =  v
  28.         end
  29.        
  30.         tAPIsLoading[sName] = nil
  31.         return tAPI
  32.     else
  33.         return nil
  34.     end
  35. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement