Guest User

class

a guest
Jan 12th, 2013
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.75 KB | None | 0 0
  1. local classEnv = { }
  2. setmetatable( classEnv, { __index = _G } )
  3.  
  4. function instance( name )
  5.  local toReturn = { }
  6.  for k,v in pairs( classEnv[name] ) do
  7.   toReturn[k] = v
  8.  end
  9.  if toReturn["default"] then toReturn["default"]( ) end
  10.  return toReturn
  11. end
  12.  
  13. function load( file, default )
  14.  
  15.  if not fs.exists( file ) then return false end
  16.  
  17.  local tEnv = { }
  18.  setmetatable( tEnv, { __index = classEnv } )
  19.  
  20.  local fClass, err = loadfile( file )
  21.  if fClass then
  22.   setfenv( fClass, tEnv )
  23.   fClass( )
  24.  else
  25.   printError( err )
  26.   return false
  27.  end
  28.  
  29.  local tClass = { }
  30.  for k,v in pairs( tEnv ) do
  31.   if k == default then
  32.    tClass["default"] = v
  33.   end
  34.   tClass[k] = v
  35.  end
  36.  
  37.  classEnv[ fs.getName( file ) ] = tClass
  38.  return true
  39.  
  40. end
Advertisement
Add Comment
Please, Sign In to add comment