diff --git a/src/osgPlugins/lua/LuaScriptEngine.cpp b/src/osgPlugins/lua/LuaScriptEngine.cpp index 39a735467..53fee2cd8 100644 --- a/src/osgPlugins/lua/LuaScriptEngine.cpp +++ b/src/osgPlugins/lua/LuaScriptEngine.cpp @@ -1605,6 +1605,62 @@ static int callImageSet(lua_State* _lua) return 0; } +////////////////////////////////////////////////////////////////////////////////////// +// +// Node Parent +// +static int callGetParent(lua_State* _lua) +{ + const LuaScriptEngine* lse = reinterpret_cast(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::Node* node = lse->getObjectFromTable(1); + if (!node) + { + OSG_NOTICE<<"Warning: Node::getParent() can only be called on a Node"<=2 && lua_isnumber(_lua, 2)) + { + index = static_cast(lua_tonumber(_lua, 2)); + if (index>=0 && index(node->getNumParents())) + { + lse->pushObject(node->getParent(0)); + return 1; + } + else + { + OSG_NOTICE<<"Warning: Call to node:getParent(index) has an out of range index."<(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::Node* node = lse->getObjectFromTable(1); + if (!node) + { + OSG_NOTICE<<"Warning: Node::getNumParents() can only be called on a Node"<getNumParents()); + return 1; +} + ////////////////////////////////////////////////////////////////////////////////////// // // Method calling support @@ -4182,6 +4238,14 @@ void LuaScriptEngine::pushObject(osg::Object* object) const luaL_getmetatable(_lua, "LuaScriptEngine.Object"); lua_setmetatable(_lua, -2); } + else if (dynamic_cast(object)!=0) + { + assignClosure("getParent", callGetParent); + assignClosure("getNumParents", callGetNumParents); + + luaL_getmetatable(_lua, "LuaScriptEngine.Object"); + lua_setmetatable(_lua, -2); + } else { luaL_getmetatable(_lua, "LuaScriptEngine.Object");