From a9f8af3fb6a0067496912bf6791406a169a91f64 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Tue, 11 Feb 2014 09:43:08 +0000 Subject: [PATCH] Changed implementation of enums to use strings as lua type to make it easier to do comparisons and track values --- src/osgPlugins/lua/LuaScriptEngine.cpp | 28 ++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/osgPlugins/lua/LuaScriptEngine.cpp b/src/osgPlugins/lua/LuaScriptEngine.cpp index afb6c4614..16e267aa6 100644 --- a/src/osgPlugins/lua/LuaScriptEngine.cpp +++ b/src/osgPlugins/lua/LuaScriptEngine.cpp @@ -584,6 +584,25 @@ int LuaScriptEngine::pushPropertyToStack(osg::Object* object, const std::string& break; } case(osgDB::BaseSerializer::RW_ENUM): + { + int value; + if (_pi.getProperty(object, propertyName, value)) + { + osgDB::BaseSerializer* serializer = _pi.getSerializer(object, propertyName, type); + osgDB::IntLookup* lookup = serializer ? serializer->getIntLookup() : 0; + if (lookup) + { + std::string enumString = lookup->getString(value); + lua_pushstring(_lua, enumString.c_str()); + } + else + { + lua_pushinteger(_lua, value); + } + return 1; + } + break; + } case(osgDB::BaseSerializer::RW_INT): { int value; @@ -1615,6 +1634,15 @@ osg::Object* LuaScriptEngine::popParameterObject() const break; } case(osgDB::BaseSerializer::RW_ENUM): + if (lua_isstring(_lua, -1)) + { + object = new osg::StringValueObject("", lua_tostring(_lua, -1)); + } + else if (lua_isnumber(_lua, -1)) + { + object = new osg::IntValueObject("", static_cast(lua_tonumber(_lua, -1))); + } + break; case(osgDB::BaseSerializer::RW_INT): { if (lua_isnumber(_lua, -1)) object = new osg::IntValueObject("", static_cast(lua_tonumber(_lua, -1)));