Added Map serializer size() method and support for it in the lua plugin. Renamed functions in lua plugin to be more consistent.
This commit is contained in:
parent
69e9f2c973
commit
9394215d31
@ -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<const C&>(obj);
|
||||
const P& map = (object.*_constgetter)();
|
||||
return map.size();
|
||||
}
|
||||
|
||||
virtual bool read( InputStream& is, osg::Object& obj )
|
||||
{
|
||||
C& object = OBJECT_CAST<C&>(obj);
|
||||
|
@ -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<const LuaScriptEngine*>(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<const LuaScriptEngine*>(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<const LuaScriptEngine*>(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<const LuaScriptEngine*>(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<const LuaScriptEngine*>(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<osgDB::MapBaseSerializer*>(bs);
|
||||
if (ms)
|
||||
{
|
||||
OSG_NOTICE<<"Doing map clear"<<std::endl;
|
||||
|
||||
ms->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<const LuaScriptEngine*>(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<osg::Object>(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<osgDB::MapBaseSerializer*>(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"<<std::endl;
|
||||
assignClosure("clear", getMapClear);
|
||||
assignClosure("clear", callMapClear);
|
||||
assignClosure("size", getMapSize);
|
||||
|
||||
luaL_getmetatable(_lua, "LuaScriptEngine.Map");
|
||||
lua_setmetatable(_lua, -2);
|
||||
@ -2949,10 +2970,10 @@ void LuaScriptEngine::pushObject(osg::Object* object) const
|
||||
lua_pushstring(_lua, "containerPropertyName"); lua_pushstring(_lua, "vector"); lua_settable(_lua, -3);
|
||||
|
||||
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);
|
||||
|
Loading…
Reference in New Issue
Block a user