Skip to content

Commit b210d0c

Browse files
authored
improve ConfigValue([value]) to support lua_type(bool, string, number) (#372)
Signed-off-by: shewer <shewer@gmail.com>
1 parent 1bde771 commit b210d0c

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

src/types.cc

+17-3
Original file line numberDiff line numberDiff line change
@@ -951,8 +951,22 @@ namespace ConfigValueReg {
951951
// an<T> make(){
952952
// return New<T>();
953953
// };
954-
an<T> make(string s){
955-
return New<T>(s);
954+
955+
int raw_make(lua_State *L) {
956+
an<T> t = New<T>();
957+
if (lua_gettop(L) > 0 && !lua_isnil(L, 1)) {
958+
if (lua_isstring(L, 1)) {
959+
t->SetString(lua_tostring(L, 1));
960+
}
961+
else if(lua_isboolean(L, 1)){
962+
t->SetBool(lua_toboolean(L, 1));
963+
}
964+
else {
965+
LOG(WARNING) << "args #1 type error: " << luaL_typename(L, 1);
966+
}
967+
}
968+
LuaType<an<T>>::pushdata(L, t);
969+
return 1;
956970
};
957971

958972
optional<bool> get_bool(T &t) {
@@ -1006,7 +1020,7 @@ namespace ConfigValueReg {
10061020
}
10071021

10081022
static const luaL_Reg funcs[] = {
1009-
{"ConfigValue", WRAP(make)},
1023+
{"ConfigValue",(raw_make)},
10101024
{ NULL, NULL },
10111025
};
10121026

0 commit comments

Comments
 (0)