From 116d724338f727b389aae5582245c9580d5805f0 Mon Sep 17 00:00:00 2001 From: satoren Date: Sun, 12 Jun 2016 06:17:18 +0900 Subject: [PATCH] setField return result --- include/kaguya/detail/lua_table_def.hpp | 29 ++++++++++++------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/include/kaguya/detail/lua_table_def.hpp b/include/kaguya/detail/lua_table_def.hpp index 6db5dfa..ee5e80b 100644 --- a/include/kaguya/detail/lua_table_def.hpp +++ b/include/kaguya/detail/lua_table_def.hpp @@ -304,77 +304,76 @@ namespace kaguya * @brief table[key] = value; */ template - void setField(const K& key, const V& value) + bool setField(const K& key, const V& value) { lua_State* state = state_(); if (!state) { except::typeMismatchError(state, "is nil"); - return; + return false; } util::ScopedSavedStack save(state); int stackIndex = pushStackIndex_(state); util::one_push(state, key);//push table key util::one_push(state, value);//push value lua_settable(state, stackIndex);//thistable[key] = value + return true; } template - void setField(const char* key, const V& value) + bool setField(const char* key, const V& value) { lua_State* state = state_(); if (!state) { except::typeMismatchError(state, "is nil"); - return; + return false; } util::ScopedSavedStack save(state); int stackIndex = pushStackIndex_(state); util::one_push(state, value);//push value lua_setfield(state, stackIndex, key);//thistable[key] = value + return true; } template - void setField(const std::string& key, const V& value) + bool setField(const std::string& key, const V& value) { - setField(key.c_str(), value); + return setField(key.c_str(), value); } #if KAGUYA_USE_CPP11 /** * @brief table[key] = value; */ template - void setField(K&& key, V&& value) + bool setField(K&& key, V&& value) { lua_State* state = state_(); if (!state) { except::typeMismatchError(state, "is nil"); - return; + return false; } util::ScopedSavedStack save(state); int stackIndex = pushStackIndex_(state); util::one_push(state, std::forward(key));//push table key util::one_push(state, std::forward(value));//push value lua_settable(state, stackIndex);//thistable[key] = value + return true; } template - void setField(const char* key, V&& value) + bool setField(const char* key, V&& value) { lua_State* state = state_(); if (!state) { except::typeMismatchError(state, "is nil"); - return; + return false; } util::ScopedSavedStack save(state); int stackIndex = pushStackIndex_(state); util::one_push(state, std::forward(value));//push value lua_setfield(state, stackIndex, key);//thistable[key] = value - } - template - void setField(const std::string& key, V&& value) - { - setField(key.c_str(), std::forward(value)); + return true; } #endif };