LayZee

ComputerCraft lzLoad

Dec 26th, 2013
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.82 KB | None | 0 0
  1. --[[
  2. /**
  3.  * lzModuleLoader
  4.  *
  5.  * Loads modules that are based on the
  6.  * JavaScript Module pattern
  7.  *
  8.  * @copyright (C) LayZee 2014
  9.  */
  10. --]]
  11.  
  12. local fileExists = function(filename)
  13.   local file = io.open(filename, 'r')
  14.  
  15.   if file == nil then
  16.     return false
  17.   end
  18.  
  19.   io.close(file)
  20.  
  21.   return true
  22. end
  23.  
  24. load = function(moduleName, aliasName)
  25.   local filename = 'lz.' .. moduleName
  26.  
  27.   assert(
  28.     fileExists(filename),
  29.     'File \'' .. filename
  30.       .. '\' does not exist'
  31.   )
  32.  
  33.   _G.lz = _G.lz or {}
  34.  
  35.   _G.lz[moduleName] = (loadfile(filename))()
  36.  
  37.   if aliasName then
  38.     _G.lz[aliasName] = _G.lz[moduleName]
  39.   end
  40.  
  41.   local moduleTitle = 'lz'
  42.     .. moduleName:gsub(
  43.       '^%l',
  44.       string.upper
  45.     )
  46.  
  47.   print(moduleTitle .. ' v'
  48.     .. _G.lz[moduleName].VERSION
  49.     .. ' loaded'
  50.   )
  51. end
Advertisement
Add Comment
Please, Sign In to add comment