Browse Source

Add ElementChildNodesProxy lua length function. (#315)

nimble0 3 years ago
parent
commit
dca367b214
2 changed files with 11 additions and 0 deletions
  1. 10 0
      Source/Lua/ElementChildNodesProxy.cpp
  2. 1 0
      Source/Lua/ElementChildNodesProxy.h

+ 10 - 0
Source/Lua/ElementChildNodesProxy.cpp

@@ -39,6 +39,8 @@ template<> void ExtraInit<ElementChildNodesProxy>(lua_State* L, int metatable_in
     lua_setfield(L,metatable_index,"__index");
     lua_pushcfunction(L,ElementChildNodesProxy__pairs);
     lua_setfield(L,metatable_index,"__pairs");
+    lua_pushcfunction(L,ElementChildNodesProxy__len);
+    lua_setfield(L,metatable_index,"__len");
 }
 
 int ElementChildNodesProxy__index(lua_State* L)
@@ -63,6 +65,14 @@ int ElementChildNodesProxy__pairs(lua_State* L)
     return MakeIntPairs(L);
 }
 
+int ElementChildNodesProxy__len(lua_State* L)
+{
+    ElementChildNodesProxy* obj = LuaType<ElementChildNodesProxy>::check(L,1);
+    RMLUI_CHECK_OBJ(obj);
+    lua_pushinteger(L, obj->owner->GetNumChildren());;
+    return 1;
+}
+
 RegType<ElementChildNodesProxy> ElementChildNodesProxyMethods[] = 
 {
     { nullptr, nullptr },

+ 1 - 0
Source/Lua/ElementChildNodesProxy.h

@@ -42,6 +42,7 @@ struct ElementChildNodesProxy { Element* owner;  };
 template<> void ExtraInit<ElementChildNodesProxy>(lua_State* L, int metatable_index);
 int ElementChildNodesProxy__index(lua_State* L);
 int ElementChildNodesProxy__pairs(lua_State* L);
+int ElementChildNodesProxy__len(lua_State* L);
 
 extern RegType<ElementChildNodesProxy> ElementChildNodesProxyMethods[];
 extern luaL_Reg ElementChildNodesProxyGetters[];