Added support for enum's in the Lua script integration
This commit is contained in:
parent
8eae4b0381
commit
1319c2d281
@ -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;
|
||||
|
@ -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<IntLookup::Value>(value)); }
|
||||
|
||||
|
@ -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<int>(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))
|
||||
|
Loading…
Reference in New Issue
Block a user