diff --git a/include/osgDB/Serializer b/include/osgDB/Serializer index 6a5562a37..f0b050904 100644 --- a/include/osgDB/Serializer +++ b/include/osgDB/Serializer @@ -1145,6 +1145,7 @@ public: virtual void setElement(osg::Object& obj, void* ptrKey, void* ptrValue) const {} virtual void* getElement(osg::Object& obj, void* ptrKey) const { return 0; } virtual const void* getElement(const osg::Object& obj, void* ptrKey) const { return 0; } + virtual unsigned int size(const osg::Object& obj) const { return 0; } protected: Type _keyType; @@ -1204,6 +1205,13 @@ public: else return &(itr->second); } + virtual unsigned int size(const osg::Object& obj) const + { + const C& object = OBJECT_CAST(obj); + const P& map = (object.*_constgetter)(); + return map.size(); + } + virtual bool read( InputStream& is, osg::Object& obj ) { C& object = OBJECT_CAST(obj); diff --git a/src/osgPlugins/lua/LuaScriptEngine.cpp b/src/osgPlugins/lua/LuaScriptEngine.cpp index 75156310b..3fa1409e3 100644 --- a/src/osgPlugins/lua/LuaScriptEngine.cpp +++ b/src/osgPlugins/lua/LuaScriptEngine.cpp @@ -223,7 +223,7 @@ static int getContainerSize(lua_State* _lua) return 0; } -static int getContainerClear(lua_State* _lua) +static int callVectorClear(lua_State* _lua) { const LuaScriptEngine* lse = reinterpret_cast(lua_topointer(_lua, lua_upvalueindex(1))); int n = lua_gettop(_lua); /* number of arguments */ @@ -245,7 +245,7 @@ static int getContainerClear(lua_State* _lua) return 0; } -static int getContainerResize(lua_State* _lua) +static int callVectorResize(lua_State* _lua) { const LuaScriptEngine* lse = reinterpret_cast(lua_topointer(_lua, lua_upvalueindex(1))); int n = lua_gettop(_lua); /* number of arguments */ @@ -267,7 +267,7 @@ static int getContainerResize(lua_State* _lua) return 0; } -static int getContainerReserve(lua_State* _lua) +static int callVectorReserve(lua_State* _lua) { const LuaScriptEngine* lse = reinterpret_cast(lua_topointer(_lua, lua_upvalueindex(1))); int n = lua_gettop(_lua); /* number of arguments */ @@ -290,7 +290,7 @@ static int getContainerReserve(lua_State* _lua) } -static int getContainerAdd(lua_State* _lua) +static int callVectorAdd(lua_State* _lua) { const LuaScriptEngine* lse = reinterpret_cast(lua_topointer(_lua, lua_upvalueindex(1))); int n = lua_gettop(_lua); /* number of arguments */ @@ -425,7 +425,7 @@ static int setMapProperty(lua_State* _lua) return 0; } -static int getMapClear(lua_State* _lua) +static int callMapClear(lua_State* _lua) { const LuaScriptEngine* lse = reinterpret_cast(lua_topointer(_lua, lua_upvalueindex(1))); int n = lua_gettop(_lua); /* number of arguments */ @@ -440,8 +440,6 @@ static int getMapClear(lua_State* _lua) osgDB::MapBaseSerializer* ms = dynamic_cast(bs); if (ms) { - OSG_NOTICE<<"Doing map clear"<clear(*object); return 0; } @@ -449,6 +447,28 @@ static int getMapClear(lua_State* _lua) return 0; } +static int getMapSize(lua_State* _lua) +{ + const LuaScriptEngine* lse = reinterpret_cast(lua_topointer(_lua, lua_upvalueindex(1))); + int n = lua_gettop(_lua); /* number of arguments */ + if (n<1 || lua_type(_lua, 1)!=LUA_TTABLE) return 0; + + osg::Object* object = lse->getObjectFromTable(1); + std::string containerPropertyName = lse->getStringFromTable(1,"containerPropertyName"); + + // check to see if Object "is a" vector + osgDB::BaseSerializer::Type type; + osgDB::BaseSerializer* bs = lse->getPropertyInterface().getSerializer(object, containerPropertyName, type); + osgDB::MapBaseSerializer* ms = dynamic_cast(bs); + if (ms) + { + lua_pushinteger(lse->getLuaState(), ms->size(*object)); + return 1; + } + + return 0; +} + ////////////////////////////////////////////////////////////////////////////////////// // // Method calling support @@ -2875,10 +2895,10 @@ void LuaScriptEngine::pushContainer(osg::Object* object, const std::string& prop if (vs) { assignClosure("size", getContainerSize); - assignClosure("clear", getContainerClear); - assignClosure("resize", getContainerResize); - assignClosure("reserve", getContainerReserve); - assignClosure("add", getContainerAdd); + assignClosure("clear", callVectorClear); + assignClosure("resize", callVectorResize); + assignClosure("reserve", callVectorReserve); + assignClosure("add", callVectorAdd); luaL_getmetatable(_lua, "LuaScriptEngine.Container"); lua_setmetatable(_lua, -2); @@ -2886,7 +2906,8 @@ void LuaScriptEngine::pushContainer(osg::Object* object, const std::string& prop else if (ms) { OSG_NOTICE<<"Need to set up map object"<