Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local classEnv = { }
- setmetatable( classEnv, { __index = _G } )
- function instance( name )
- local toReturn = { }
- for k,v in pairs( classEnv[name] ) do
- toReturn[k] = v
- end
- if toReturn["default"] then toReturn["default"]( ) end
- return toReturn
- end
- function load( file, default )
- if not fs.exists( file ) then return false end
- local tEnv = { }
- setmetatable( tEnv, { __index = classEnv } )
- local fClass, err = loadfile( file )
- if fClass then
- setfenv( fClass, tEnv )
- fClass( )
- else
- printError( err )
- return false
- end
- local tClass = { }
- for k,v in pairs( tEnv ) do
- if k == default then
- tClass["default"] = v
- end
- tClass[k] = v
- end
- classEnv[ fs.getName( file ) ] = tClass
- return true
- end
Advertisement
Add Comment
Please, Sign In to add comment