From 2944522053873952e858dfab3aa822fefd67a309 Mon Sep 17 00:00:00 2001 From: xx Date: Sun, 9 Jun 2024 23:37:23 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=94=B9set=5Fobj=E3=80=81get=5Fobj?= =?UTF-8?q?=E4=B8=BAset=5Fstr=E5=92=8Cget=5Fstr=EF=BC=8C=E4=BB=A5=E8=A7=A3?= =?UTF-8?q?=E5=86=B3=E5=A4=9A=E7=BA=BF=E7=A8=8B=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/core/global.cpp | 10 ++++------ src/core/global.h | 7 +++---- src/module/globalfuns.cpp | 12 ++++++------ src/module/globalfuns.h | 8 ++++---- 4 files changed, 17 insertions(+), 20 deletions(-) diff --git a/src/core/global.cpp b/src/core/global.cpp index 836c1e4..ecf21c0 100644 --- a/src/core/global.cpp +++ b/src/core/global.cpp @@ -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); } diff --git a/src/core/global.h b/src/core/global.h index e245451..d1abc8a 100644 --- a/src/core/global.h +++ b/src/core/global.h @@ -35,22 +35,21 @@ namespace fastweb /// 取对象 /// /// - /// /// - sol::object get_obj(const std::string& name, sol::this_state s); + sol::object get_str(const std::string& name, sol::this_state s); /// /// 置对象 /// /// /// - void set_obj(const std::string& name, sol::object value); + void set_str(const std::string& name, std::string value); /// /// 清理 /// void clear(); private: ylib::map m_ptrs; - ylib::map m_values; + ylib::map m_values; }; } diff --git a/src/module/globalfuns.cpp b/src/module/globalfuns.cpp index b5088ff..f11aff8 100644 --- a/src/module/globalfuns.cpp +++ b/src/module/globalfuns.cpp @@ -8,8 +8,8 @@ static ylib::counter 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) { diff --git a/src/module/globalfuns.h b/src/module/globalfuns.h index b639077..a5fb64b 100644 --- a/src/module/globalfuns.h +++ b/src/module/globalfuns.h @@ -27,18 +27,18 @@ namespace module static bool set_ptr(const std::string& name, void* ptr, sol::this_state ts); /// - /// 置全局对象 + /// 置全局文本 /// /// /// - 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); /// - /// 取全局对象 + /// 取全局文本 /// /// /// /// - 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); /// /// 抛出异常 ///