From 0d717293352bcd2af2b8f56ba9450c5370cea100 Mon Sep 17 00:00:00 2001 From: shewer Date: Sat, 2 Nov 2024 01:46:01 +0800 Subject: [PATCH] improve ConfigValue([value]) to support lua_type(bool, string, number) Signed-off-by: shewer --- src/types.cc | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/types.cc b/src/types.cc index 5b8ad9b..0089ddb 100644 --- a/src/types.cc +++ b/src/types.cc @@ -951,8 +951,22 @@ namespace ConfigValueReg { // an make(){ // return New(); // }; - an make(string s){ - return New(s); + + int raw_make(lua_State *L) { + an t = New(); + if (lua_gettop(L) > 0 && !lua_isnil(L, 1)) { + if (lua_isstring(L, 1)) { + t->SetString(lua_tostring(L, 1)); + } + else if(lua_isboolean(L, 1)){ + t->SetBool(lua_toboolean(L, 1)); + } + else { + LOG(WARNING) << "args #1 type error: " << luaL_typename(L, 1); + } + } + LuaType>::pushdata(L, t); + return 1; }; optional get_bool(T &t) { @@ -1006,7 +1020,7 @@ namespace ConfigValueReg { } static const luaL_Reg funcs[] = { - {"ConfigValue", WRAP(make)}, + {"ConfigValue",(raw_make)}, { NULL, NULL }, };