Alex Ames  committed 3c54015

Adding luaU_optfield

  • Participants
  • Parent commits efbaa67
  • Branches default

Comments (0)

Files changed (1)

File luawrapperutil.hpp

 template <typename U>
+inline U luaU_optfield(lua_State* L, int index, const char* field, const U& fallback = U())
+#ifndef LUAW_NO_CXX11
+    static_assert(!LUAW_STD::is_same<U, const char*>::value,
+        "luaU_getfield is not safe to use on const char*'s. (The string will be popped from the stack.)");
+    lua_getfield(L, index, field);
+    U val = luaU_opt<U>(L, -1, fallback);
+    lua_pop(L, 1);
+    return val;
+template <typename U>
 inline void luaU_setfield(lua_State* L, int index, const char* field, U val)
     luaU_push<U>(L, val);