MCPcopy Create free account
hub / github.com/defold/defold / LuaSetParent

Function LuaSetParent

engine/gui/src/gui_script.cpp:3782–3812  ·  view source on GitHub ↗

sets the parent of the node * Sets the parent node of the specified node. * * @name gui.set_parent * @param node [type:node] node for which to set its parent * @param [parent] [type:node] parent node to set, pass `nil` to remove parent * @param [keep_scene_transform] [type:boolean] optional flag to make the scene position being perserved */

Source from the content-addressed store, hash-verified

3780 * @param [keep_scene_transform] [type:boolean] optional flag to make the scene position being perserved
3781 */
3782 static int LuaSetParent(lua_State* L)
3783 {
3784 int top = lua_gettop(L);
3785
3786 HNode hnode;
3787 InternalNode* n = LuaCheckNodeInternal(L, 1, &hnode);
3788 if(n->m_Node.m_IsBone) {
3789 return 0;
3790 }
3791 HNode parent = INVALID_HANDLE;
3792 if (!lua_isnil(L, 2))
3793 {
3794 parent = GetNodeHandle(LuaCheckNodeInternal(L, 2, &hnode));
3795 }
3796 bool keep_scene_transform = false;
3797 if (top > 2 && lua_isboolean(L, 3) && lua_toboolean(L, 3))
3798 {
3799 keep_scene_transform = true;
3800 }
3801 Scene* scene = GuiScriptInstance_Check(L);
3802 dmGui::Result result = dmGui::SetNodeParent(scene, GetNodeHandle(n), parent, keep_scene_transform);
3803 switch (result)
3804 {
3805 case dmGui::RESULT_INF_RECURSION:
3806 return luaL_error(L, "Unable to set parent since it would cause an infinite loop");
3807 case dmGui::RESULT_OK:
3808 return 0;
3809 default:
3810 return luaL_error(L, "An unexpected error occurred");
3811 }
3812 }
3813
3814 /*# clone a node
3815 * Make a clone instance of a node. The cloned node will be identical to the

Callers

nothing calls this directly

Calls 7

lua_gettopFunction · 0.85
LuaCheckNodeInternalFunction · 0.85
lua_tobooleanFunction · 0.85
GuiScriptInstance_CheckFunction · 0.85
luaL_errorFunction · 0.85
GetNodeHandleFunction · 0.70
SetNodeParentFunction · 0.70

Tested by

no test coverage detected