源战役客户端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

41 line
1.2 KiB

  1. local require = require
  2. local string = string
  3. local table = table
  4. function import(moduleName, currentModuleName)
  5. local currentModuleNameParts
  6. local moduleFullName = moduleName
  7. local offset = 1
  8. while true do
  9. if string.byte(moduleName, offset) ~= 46 then -- .
  10. moduleFullName = string.sub(moduleName, offset)
  11. if currentModuleNameParts and #currentModuleNameParts > 0 then
  12. moduleFullName = table.concat(currentModuleNameParts, ".") .. "." .. moduleFullName
  13. end
  14. break
  15. end
  16. offset = offset + 1
  17. if not currentModuleNameParts then
  18. if not currentModuleName then
  19. local n,v = debug.getlocal(3, 1)
  20. currentModuleName = v
  21. end
  22. currentModuleNameParts = string.split(currentModuleName, ".")
  23. end
  24. table.remove(currentModuleNameParts, #currentModuleNameParts)
  25. end
  26. return require(moduleFullName)
  27. end
  28. --重新require一个lua文件,替代系统文件。
  29. function reimport(name)
  30. local package = package
  31. package.loaded[name] = nil
  32. package.preload[name] = nil
  33. return require(name)
  34. end