Barnet

loadasmodule.lua

Jun 9th, 2021
539
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. -- os.loadAPI sucks >.>
  3. local function loadAsModule(f)
  4.   local x = assert(loadfile(f))
  5.   local mt = {__index = getfenv()}
  6.   local env = setmetatable({}, mt)
  7.   setfenv(x, env)
  8.   x()
  9.   local ret = {}
  10.   for k,v in pairs(env) do
  11.     ret[k] = v
  12.   end
  13.   return ret
  14. end
  15.  
  16. return {loadAsModule = loadAsModule}
RAW Paste Data