diff --git a/src/osgPlugins/lua/LuaScriptEngine.cpp b/src/osgPlugins/lua/LuaScriptEngine.cpp index 821ff914f..ba91e953e 100644 --- a/src/osgPlugins/lua/LuaScriptEngine.cpp +++ b/src/osgPlugins/lua/LuaScriptEngine.cpp @@ -755,19 +755,44 @@ static int callStateSetSet(lua_State* _lua) } else if (lua_type(_lua,2)==LUA_TSTRING) { - std::string modeString = lua_tostring(_lua, 2); - GLenum mode = lse->lookUpGLenumValue(modeString); + std::string key = lua_tostring(_lua, 2); + GLenum mode = lse->lookUpGLenumValue(key); if (n>=3) { - osg::StateAttribute::OverrideValue value=osg::StateAttribute::ON; - bool setOnOff = false; - if (lua_type(_lua,3)==LUA_TSTRING) + if (mode) { - value = convertStringToStateAttributeValue(lua_tostring(_lua, 3), value, setOnOff); - } + osg::StateAttribute::OverrideValue value=osg::StateAttribute::ON; + bool setOnOff = false; + if (lua_type(_lua,3)==LUA_TSTRING) + { + value = convertStringToStateAttributeValue(lua_tostring(_lua, 3), value, setOnOff); + } - stateset->setMode(mode, value); - return 0; + stateset->setMode(mode, value); + return 0; + } + else + { + std::string value; + if (lua_type(_lua,3)==LUA_TSTRING) + { + value = lua_tostring(_lua, 3); + } + stateset->setDefine(key, value); + } + } + else + { + if (mode) + { + osg::StateAttribute::OverrideValue value=osg::StateAttribute::ON; + stateset->setMode(mode, value); + return 0; + } + else + { + stateset->setDefine(key); + } } } @@ -982,6 +1007,19 @@ static int callStateSetGet(lua_State* _lua) } } + + const osg::StateSet::DefineList& dl = stateset->getDefineList(); + for(osg::StateSet::DefineList::const_iterator itr = dl.begin(); + itr != dl.end(); + ++itr) + { + if (value == itr->first) + { + lua_pushstring(_lua, itr->second.first.c_str()); + return 1; + } + } + OSG_NOTICE<<"Warning: StateSet:get("<getDefineList(); + for(osg::StateSet::DefineList::const_iterator itr = dl.begin(); + itr != dl.end(); + ++itr) + { + if (value == itr->first) + { + stateset->removeDefine(value); + return 0; + } + } + osg::StateAttribute::GLMode mode = lse->lookUpGLenumValue(value); const osg::StateSet::ModeList& ml = stateset->getModeList(); for(osg::StateSet::ModeList::const_iterator itr = ml.begin();