优化
This commit is contained in:
@@ -15,7 +15,7 @@ void fastweb::global::regist(sol::state* lua)
|
||||
for_iter(iter, (*m_ptrs.parent()))
|
||||
{
|
||||
auto im = static_cast<module::base*>(iter->second);
|
||||
im->regist_global(iter->first, lua);
|
||||
im->regist_global(iter->first.c_str(), lua);
|
||||
}
|
||||
m_ptrs.unlock();
|
||||
}
|
||||
|
||||
@@ -83,18 +83,34 @@ void fastweb::subscribe_manager::exec(const std::string& filepath, network::http
|
||||
std::string exception_string;
|
||||
try
|
||||
{
|
||||
auto lbResult = lua->state->load_file(filepath);
|
||||
if (lbResult.valid() == false)
|
||||
{
|
||||
sol::error err = lbResult;
|
||||
throw ylib::exception("Failed to load script, " + std::string(err.what()));
|
||||
//auto lbResult = lua->state->load_file(filepath);
|
||||
//if (lbResult.valid() == false)
|
||||
//{
|
||||
// sol::error err = lbResult;
|
||||
// throw ylib::exception("Failed to load script, " + std::string(err.what()));
|
||||
//}
|
||||
//module::request m_request(request);
|
||||
//module::response m_response(response);
|
||||
|
||||
//(*lua->state)["response"] = &m_response;
|
||||
//(*lua->state)["request"] = &m_request;
|
||||
//lbResult();
|
||||
|
||||
sol::load_result script = lua->state->load_file(filepath);
|
||||
if (!script.valid()) {
|
||||
sol::error err = script;
|
||||
throw ylib::exception(err.what());
|
||||
}
|
||||
module::request m_request(request);
|
||||
module::response m_response(response);
|
||||
|
||||
(*lua->state)["response"] = &m_response;
|
||||
(*lua->state)["request"] = &m_request;
|
||||
lbResult();
|
||||
|
||||
sol::protected_function_result result = script();
|
||||
if (!result.valid()) {
|
||||
sol::error err = result;
|
||||
throw ylib::exception(err.what());
|
||||
}
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
|
||||
@@ -14,7 +14,7 @@ namespace module
|
||||
/// </summary>
|
||||
/// <param name="name"></param>
|
||||
/// <param name="lua"></param>
|
||||
virtual void regist_global(const std::string& name,sol::state* lua) = 0;
|
||||
virtual void regist_global(const char* name, sol::state* lua) = 0;
|
||||
/// <summary>
|
||||
/// 释放全局变量(global类管理)
|
||||
/// </summary>
|
||||
|
||||
@@ -34,7 +34,7 @@ void module::mutex::regist(sol::state* lua)
|
||||
);
|
||||
}
|
||||
|
||||
void module::mutex::regist_global(const std::string& name, sol::state* lua)
|
||||
void module::mutex::regist_global(const char* name, sol::state* lua)
|
||||
{
|
||||
lua->registry()[name] = this;
|
||||
(*lua)[name] = this;
|
||||
|
||||
@@ -27,7 +27,7 @@ namespace module
|
||||
static void regist(sol::state* lua);
|
||||
private:
|
||||
// 通过 imodule 继承
|
||||
virtual void regist_global(const std::string& name, sol::state* lua);
|
||||
virtual void regist_global(const char* name, sol::state* lua);
|
||||
virtual void delete_global() { delete this; }
|
||||
std::mutex m_mutex;
|
||||
};
|
||||
|
||||
@@ -66,7 +66,7 @@ void module::timer::regist(sol::state* lua)
|
||||
);
|
||||
}
|
||||
|
||||
void module::timer::regist_global(const std::string& name, sol::state* lua)
|
||||
void module::timer::regist_global(const char* name, sol::state* lua)
|
||||
{
|
||||
lua->registry()[name] = this;
|
||||
(*lua)[name] = this;
|
||||
|
||||
@@ -41,7 +41,7 @@ namespace module
|
||||
/// <param name="name"></param>
|
||||
void remove(const std::string& name, sol::this_state ts);
|
||||
static void regist(sol::state* lua);
|
||||
virtual void regist_global(const std::string& name, sol::state* lua) override;
|
||||
virtual void regist_global(const char* name, sol::state* lua) override;
|
||||
virtual void delete_global() { delete this; }
|
||||
private:
|
||||
|
||||
|
||||
Reference in New Issue
Block a user