xx 2 лет назад
Родитель
Сommit
efc5acbfe5
7 измененных файлов с 29 добавлено и 13 удалено
  1. 1 1
      src/core/global.cpp
  2. 23 7
      src/core/subscribemanager.cpp
  3. 1 1
      src/module/basemodule.h
  4. 1 1
      src/module/mutex.cpp
  5. 1 1
      src/module/mutex.h
  6. 1 1
      src/module/timer.cpp
  7. 1 1
      src/module/timer.h

+ 1 - 1
src/core/global.cpp

@@ -15,7 +15,7 @@ void fastweb::global::regist(sol::state* lua)
 	for_iter(iter, (*m_ptrs.parent()))
 	for_iter(iter, (*m_ptrs.parent()))
 	{
 	{
 		auto im = static_cast<module::base*>(iter->second);
 		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();
 	m_ptrs.unlock();
 }
 }

+ 23 - 7
src/core/subscribemanager.cpp

@@ -83,18 +83,34 @@ void fastweb::subscribe_manager::exec(const std::string& filepath, network::http
 	std::string exception_string;
 	std::string exception_string;
 	try
 	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::request m_request(request);
 		module::response m_response(response);
 		module::response m_response(response);
-
 		(*lua->state)["response"] = &m_response;
 		(*lua->state)["response"] = &m_response;
 		(*lua->state)["request"] = &m_request;
 		(*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)
 	catch (const std::exception& e)
 	{
 	{

+ 1 - 1
src/module/basemodule.h

@@ -14,7 +14,7 @@ namespace module
 		/// </summary>
 		/// </summary>
 		/// <param name="name"></param>
 		/// <param name="name"></param>
 		/// <param name="lua"></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>
 		/// <summary>
 		/// 释放全局变量(global类管理)
 		/// 释放全局变量(global类管理)
 		/// </summary>
 		/// </summary>

+ 1 - 1
src/module/mutex.cpp

@@ -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->registry()[name] = this;
     (*lua)[name] = this;
     (*lua)[name] = this;

+ 1 - 1
src/module/mutex.h

@@ -27,7 +27,7 @@ namespace module
 		static void regist(sol::state* lua);
 		static void regist(sol::state* lua);
 	private:
 	private:
 		// 通过 imodule 继承
 		// 通过 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; }
 		virtual void delete_global() { delete this; }
 		std::mutex m_mutex;
 		std::mutex m_mutex;
 	};
 	};

+ 1 - 1
src/module/timer.cpp

@@ -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->registry()[name] = this;
     (*lua)[name] = this;
     (*lua)[name] = this;

+ 1 - 1
src/module/timer.h

@@ -41,7 +41,7 @@ namespace module
 		/// <param name="name"></param>
 		/// <param name="name"></param>
 		void remove(const std::string& name, sol::this_state ts);
 		void remove(const std::string& name, sol::this_state ts);
 		static void regist(sol::state* lua);
 		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; }
 		virtual void delete_global() { delete this; }
 	private:
 	private: