Files
fastmovieai/fastmovie-admin/lua/test.lua
T
李建琦 eae151fd57 FastMovieAI AI短剧创作平台 二开基线
- 源码: xhadmincn/FastMovieAI (Apache 2.0)
- 二开: Docker部署, Swoole改Select, route.php修复, 补update/VERSION
- vendor/示例资源已gitignore
2026-08-26 18:37:36 +08:00

39 lines
1.0 KiB
Lua

local function get_script_dir()
local lfs_ok, lfs = pcall(require, "lfs")
local source
if debug and debug.getinfo then
-- OpenResty 或标准 Lua 都适用
source = debug.getinfo(2, "S").source:sub(2)
elseif arg and arg[0] then
source = arg[0]
else
return nil
end
-- 如果是相对路径,转换为绝对路径
if not source:match("^/") then
if lfs_ok then
source = lfs.currentdir() .. "/" .. source
else
-- 没有 lfs,使用 io.popen("pwd") 获取当前目录
local handle = io.popen("pwd")
local cwd = handle:read("*l")
handle:close()
source = cwd .. "/" .. source
end
end
-- 提取目录
local dir = source:match("(.*/)")
return dir
end
package.path = package.path .. ";"..get_script_dir().."module/?.lua;"
local env = require("load_env")
print("ENV文件加载成功,服务名称:"..env.get("SERVER_NAME"))
-- 测试
print(get_script_dir())