diff --git a/include/osgDB/PropertyInterface b/include/osgDB/PropertyInterface index ddf4a4459..6fd40eb68 100644 --- a/include/osgDB/PropertyInterface +++ b/include/osgDB/PropertyInterface @@ -184,6 +184,10 @@ public: /// Get the const list of properties that are explictly defined as not supported const ObjectPropertyMap& getBlackList() const { return _blackList; } + osgDB::ObjectWrapper* getObjectWrapper(const osg::Object* object) const; + + osgDB::BaseSerializer* getSerializer(const osg::Object* object, const std::string& propertyName, osgDB::BaseSerializer::Type& type) const; + protected: bool copyPropertyDataFromObject(const osg::Object* object, const std::string& propertyName, void* valuePtr, unsigned int valueSize, osgDB::BaseSerializer::Type valueType); @@ -194,9 +198,7 @@ protected: bool copyPropertyObjectToObject(osg::Object* object, const std::string& propertyName, const void* valuePtr, unsigned int valueSize, osgDB::BaseSerializer::Type valueType); - osgDB::ObjectWrapper* getObjectWrapper(const osg::Object* object) const; - osgDB::BaseSerializer* getSerializer(const osg::Object* object, const std::string& propertyName, osgDB::BaseSerializer::Type& type) const; osgDB::OutputStream _outputStream; PropertyOutputIterator* _poi; diff --git a/include/osgDB/Serializer b/include/osgDB/Serializer index a28dbcd53..b8f9c6fd8 100644 --- a/include/osgDB/Serializer +++ b/include/osgDB/Serializer @@ -145,6 +145,8 @@ public: virtual bool write( OutputStream&, const osg::Object& ) = 0; virtual const std::string& getName() const = 0; + virtual IntLookup* getIntLookup() { return 0; } + protected: int _firstVersion; // Library version when the serializer is first introduced int _lastVersion; // Library version when the serializer is last required. @@ -654,6 +656,8 @@ public: EnumSerializer( const char* name, P def, Getter gf, Setter sf ) : ParentType(name, def), _getter(gf), _setter(sf) {} + virtual IntLookup* getIntLookup() { return &_lookup; } + void add( const char* str, P value ) { _lookup.add(str, static_cast(value)); } diff --git a/src/osgPlugins/lua/LuaScriptEngine.cpp b/src/osgPlugins/lua/LuaScriptEngine.cpp index c81b64d99..36aef26fa 100644 --- a/src/osgPlugins/lua/LuaScriptEngine.cpp +++ b/src/osgPlugins/lua/LuaScriptEngine.cpp @@ -761,6 +761,26 @@ int LuaScriptEngine::setPropertyFromStack(osg::Object* object, const std::string break; } case(osgDB::BaseSerializer::RW_ENUM): + { + if (lua_isnumber(_lua, -1)) + { + _pi.setProperty(object, propertyName, static_cast(lua_tonumber(_lua, -1))); + return 0; + } + else if (lua_isstring(_lua, -1)) + { + const char* enumString = lua_tostring(_lua, -1); + osgDB::BaseSerializer* serializer = _pi.getSerializer(object, propertyName, type); + osgDB::IntLookup* lookup = serializer ? serializer->getIntLookup() : 0; + if (lookup) + { + int value = lookup->getValue(enumString); + _pi.setProperty(object, propertyName, value); + } + return 0; + } + break; + } case(osgDB::BaseSerializer::RW_INT): { if (lua_isnumber(_lua, -1))