更改set_obj、get_obj为set_str和get_str,以解决多线程问题

This commit is contained in:
xx
2024-06-09 23:37:23 +08:00
parent cd45a258d6
commit 2944522053
4 changed files with 17 additions and 20 deletions

View File

@@ -37,17 +37,15 @@ bool fastweb::global::set_ptr(const std::string& name, void* value, sol::this_st
return m_ptrs.add(name, value);
}
sol::object fastweb::global::get_obj(const std::string& name, sol::this_state s)
sol::object fastweb::global::get_str(const std::string& name, sol::this_state s)
{
sol::object value;
std::string value;
if (m_values.get(name, value))
{
return value;
}
return sol::make_object(s, value);
return sol::make_object(s, sol::nil);
}
void fastweb::global::set_obj(const std::string& name, sol::object value)
void fastweb::global::set_str(const std::string& name, std::string value)
{
m_values.set(name, value, true);
}

View File

@@ -35,22 +35,21 @@ namespace fastweb
/// 取对象
/// </summary>
/// <param name="name"></param>
/// <param name="s"></param>
/// <returns></returns>
sol::object get_obj(const std::string& name, sol::this_state s);
sol::object get_str(const std::string& name, sol::this_state s);
/// <summary>
/// 置对象
/// </summary>
/// <param name="name"></param>
/// <param name="value"></param>
void set_obj(const std::string& name, sol::object value);
void set_str(const std::string& name, std::string value);
/// <summary>
/// 清理
/// </summary>
void clear();
private:
ylib::map<std::string, void*> m_ptrs;
ylib::map<std::string, sol::object> m_values;
ylib::map<std::string,std::string> m_values;
};
}

View File

@@ -8,8 +8,8 @@ static ylib::counter<uint64> s_counter_guid;
void module::globalfuncs::regist(sol::state* lua)
{
lua->set_function("set_ptr", module::globalfuncs::set_ptr);
lua->set_function("get_obj", module::globalfuncs::get_obj);
lua->set_function("set_obj", module::globalfuncs::set_obj);
lua->set_function("get_str", module::globalfuncs::get_str);
lua->set_function("set_str", module::globalfuncs::set_str);
lua->set_function("make_software_guid", module::globalfuncs::make_software_guid);
lua->set_function("throw_string", module::globalfuncs::throw_string);
lua->set_function("print", module::globalfuncs::print);
@@ -50,16 +50,16 @@ bool module::globalfuncs::set_ptr(const std::string& name, void* ptr, sol::this_
return app->global->set_ptr(name,ptr, ts);
}
void module::globalfuncs::set_obj(const std::string& name, sol::object value, sol::this_state ts)
void module::globalfuncs::set_str(const std::string& name, std::string value, sol::this_state ts)
{
GET_APP;
return app->global->set_obj(name,value);
return app->global->set_str(name,value);
}
sol::object module::globalfuncs::get_obj(const std::string& name, sol::this_state ts)
sol::object module::globalfuncs::get_str(const std::string& name, sol::this_state ts)
{
GET_APP;
return app->global->get_obj(name, ts);
return app->global->get_str(name, ts);
}
void module::globalfuncs::throw_string(const std::string& msg)
{

View File

@@ -27,18 +27,18 @@ namespace module
static bool set_ptr(const std::string& name, void* ptr, sol::this_state ts);
/// <summary>
/// 置全局对象
/// 置全局文本
/// </summary>
/// <param name="name"></param>
/// <param name="value"></param>
static void set_obj(const std::string& name, sol::object value, sol::this_state ts);
static void set_str(const std::string& name,std::string value, sol::this_state ts);
/// <summary>
/// 取全局对象
/// 取全局文本
/// </summary>
/// <param name="name"></param>
/// <param name="s"></param>
/// <returns></returns>
static sol::object get_obj(const std::string& name, sol::this_state s);
static sol::object get_str(const std::string& name, sol::this_state s);
/// <summary>
/// 抛出异常
/// </summary>