支持多lua库目录
This commit is contained in:
@@ -171,9 +171,5 @@ install(DIRECTORY ${PROJECT_SOURCE_DIR}/config DESTINATION bin/release)
|
||||
install(FILES ${PROJECT_SOURCE_DIR}/src/core/entry.h DESTINATION include)
|
||||
|
||||
|
||||
if(MSVC)
|
||||
install(FILES 3rdparty/luarocks.exe DESTINATION bin/debug/3rdparty)
|
||||
install(FILES 3rdparty/luarocks.exe DESTINATION bin/release/3rdparty)
|
||||
endif()
|
||||
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ base=${current_dir}
|
||||
; 考虑安全性,请勿放置于网站静态文件目录
|
||||
app_dir=${base}/scripts/app
|
||||
; LUA库目录
|
||||
lib_dir=${base}/scripts/lib
|
||||
lib_dir=["${base}/scripts/lib"]
|
||||
; 模块目录
|
||||
module_dir=${base}/module
|
||||
; LUA虚拟机缓存数量(并发越高越大)-建议:10
|
||||
@@ -24,8 +24,8 @@ auto_update_sec=3
|
||||
static_dir=${base}/www
|
||||
; 默认页面-404
|
||||
default_404=page/404.html
|
||||
; 默认首页(index.html,index.htm,index.lua)
|
||||
default_index=index.html
|
||||
; 默认首页(["index.html","index.htm","index.lua"])
|
||||
default_index=["index.html"]
|
||||
; SESSION保存目录
|
||||
session_dir=${base}/session
|
||||
; SESSION默认过期时间
|
||||
|
||||
@@ -64,15 +64,23 @@ std::vector<std::string> config::lua_app_files()
|
||||
std::vector<std::string> config::lua_lib_files()
|
||||
{
|
||||
std::vector<std::string> results;
|
||||
auto luas = ylib::file::traverse(sConfig->scripts.lib_dir, "(.*\\.lua)");
|
||||
for_iter(iter, luas)
|
||||
for (size_t i = 0; i < sConfig->scripts.lib_dir.size(); i++)
|
||||
{
|
||||
if (iter->second == IS_DIRECTORY)
|
||||
continue;
|
||||
std::string path = strutils::replace(iter->first, '\\', '/');
|
||||
|
||||
results.push_back(path);
|
||||
auto luas = ylib::file::traverse(sConfig->scripts.lib_dir[i], "(.*\\.lua)");
|
||||
for_iter(iter, luas)
|
||||
{
|
||||
if (iter->second == IS_DIRECTORY)
|
||||
continue;
|
||||
std::string path = sConfig->scripts.lib_dir[i]+"/"+ strutils::replace(iter->first, '\\', '/');
|
||||
results.push_back(path);
|
||||
}
|
||||
}
|
||||
// 去重
|
||||
std::sort(results.begin(), results.end());
|
||||
auto newEnd = std::unique(results.begin(), results.end());
|
||||
results.erase(newEnd, results.end());
|
||||
|
||||
|
||||
return results;
|
||||
}
|
||||
std::vector<std::string> config::extractVariableNames(const std::string& text)
|
||||
@@ -93,7 +101,7 @@ void config::cache()
|
||||
{
|
||||
|
||||
scripts.app_dir = m_ini.read("scripts","app_dir");
|
||||
scripts.lib_dir = m_ini.read("scripts", "lib_dir");
|
||||
scripts.lib_dir = ylib::json::from(m_ini.read("scripts", "lib_dir")).to<std::vector<std::string>>();
|
||||
scripts.module_dir = m_ini.read("scripts", "module_dir");
|
||||
scripts.lua_cache_size = ylib::stoi(m_ini.read("scripts", "lua_cache_size"));
|
||||
scripts.app_mapping_dir = m_ini.read("scripts", "app_mapping_dir");
|
||||
@@ -101,7 +109,7 @@ void config::cache()
|
||||
|
||||
website.static_dir = m_ini.read("website","static_dir");
|
||||
website.default_404 = m_ini.read("website", "default_404");
|
||||
website.default_index = strutils::split(m_ini.read("website", "default_index"), ',');
|
||||
website.default_index = ylib::json::from(m_ini.read("website", "default_index")).to<std::vector<std::string>>();
|
||||
website.session_dir = m_ini.read("website", "session_dir");
|
||||
website.session_timeout_sec = ylib::stoi(m_ini.read("website", "session_timeout_sec"));
|
||||
website.Initialization_script = m_ini.read("website", "Initialization_script");
|
||||
|
||||
@@ -13,7 +13,7 @@ public:
|
||||
};
|
||||
struct scripts {
|
||||
std::string app_dir;
|
||||
std::string lib_dir;
|
||||
std::vector<std::string> lib_dir;
|
||||
std::string module_dir;
|
||||
uint32 lua_cache_size = 0;
|
||||
std::string app_mapping_dir;
|
||||
|
||||
@@ -23,7 +23,7 @@ bool lualib_detecter::changed()
|
||||
changed = true;
|
||||
break;
|
||||
}
|
||||
if (ylib::file::last_write_time(sConfig->scripts.lib_dir+"/"+ lib_files[i]) != iter->second)
|
||||
if (ylib::file::last_write_time(lib_files[i]) != iter->second)
|
||||
{
|
||||
changed = true;
|
||||
break;
|
||||
@@ -39,7 +39,7 @@ bool lualib_detecter::changed()
|
||||
|
||||
m_files.clear();
|
||||
for (size_t i = 0; i < lib_files.size(); i++)
|
||||
m_files.emplace(lib_files[i], ylib::file::last_write_time(sConfig->scripts.lib_dir + "/" + lib_files[i]));
|
||||
m_files.emplace(lib_files[i], ylib::file::last_write_time(lib_files[i]));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -82,6 +82,17 @@ void module_manager::load(sol::state* lua)
|
||||
load_3rdparty(lua);
|
||||
}
|
||||
|
||||
std::string module_manager::search(const std::string& filepath)
|
||||
{
|
||||
for (size_t i = 0; i < sConfig->scripts.lib_dir.size(); i++)
|
||||
{
|
||||
std::string path = sConfig->scripts.lib_dir[i] + "/" + filepath;
|
||||
if (ylib::file::exist(path))
|
||||
return path;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
void module_manager::load_core(sol::state* lua)
|
||||
{
|
||||
lua->open_libraries(
|
||||
@@ -138,7 +149,8 @@ void module_manager::load_lualib(sol::state* lua)
|
||||
{
|
||||
// 获取当前的package.path,添加新的搜索路径
|
||||
std::string current_path = (*lua)["package"]["path"]; // 获取当前的路径
|
||||
current_path += ";" + sConfig->scripts.lib_dir + "/?.lua"; // 添加新的路径
|
||||
for (size_t i = 0; i < sConfig->scripts.lib_dir.size(); i++)
|
||||
current_path += ";" + sConfig->scripts.lib_dir[i] + "/?.lua"; // 添加新的路径
|
||||
(*lua)["package"]["path"] = current_path; // 设置修改后的路径
|
||||
}
|
||||
|
||||
|
||||
@@ -22,6 +22,12 @@ public:
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
void load(sol::state* lua);
|
||||
/// <summary>
|
||||
/// 搜索LUA
|
||||
/// </summary>
|
||||
/// <param name="filepath"></param>
|
||||
/// <returns></returns>
|
||||
std::string search(const std::string& filepath);
|
||||
private:
|
||||
/// <summary>
|
||||
/// 加载核心库
|
||||
|
||||
@@ -14,10 +14,19 @@ std::string module::timer::add(const std::string& name, const std::string& filep
|
||||
std::string filepath2;
|
||||
if (ylib::file::exist(sConfig->scripts.app_dir + "/" + filepath))
|
||||
filepath2 = sConfig->scripts.app_dir + "/" + filepath;
|
||||
else if (ylib::file::exist(sConfig->scripts.lib_dir + "/" + filepath))
|
||||
filepath2 = sConfig->scripts.lib_dir + "/" + filepath;
|
||||
else
|
||||
return "not found script lua, App: " + std::string(sConfig->scripts.app_dir + "/" + filepath) + "\r\n" + std::string(sConfig->scripts.lib_dir + "/" + filepath);
|
||||
{
|
||||
std::string filepath2 = module_manager::getInstance()->search(filepath);
|
||||
if (filepath2.empty())
|
||||
{
|
||||
std::string result;
|
||||
result = "not found script lua, App: " + std::string(sConfig->scripts.app_dir + "/" + filepath) + "\r\n Lib: ";
|
||||
for (size_t i = 0; i < sConfig->scripts.lib_dir.size(); i++)
|
||||
result.append(std::string(sConfig->scripts.lib_dir[i] + "/" + filepath)+"\r\n");
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
std::unique_lock<std::mutex> uni(module::timer::getInstance()->m_mutex);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user