clone a node including its children * Make a clone instance of a node and all its children. * Use gui.clone to clone a node excluding its children. * * @name gui.clone_tree * @param node [type:node] root node to clone * @return clones [type:table] a table mapping node ids to the corresponding cloned nodes */
| 3922 | * @return clones [type:table] a table mapping node ids to the corresponding cloned nodes |
| 3923 | */ |
| 3924 | static int LuaCloneTree(lua_State* L) |
| 3925 | { |
| 3926 | int top = lua_gettop(L); |
| 3927 | (void)top; |
| 3928 | |
| 3929 | lua_newtable(L); |
| 3930 | |
| 3931 | // Set meta table to convert string indices to hashes |
| 3932 | lua_createtable(L, 0, 1); |
| 3933 | lua_pushcfunction(L, HashTableIndex); |
| 3934 | lua_setfield(L, -2, "__index"); |
| 3935 | lua_setmetatable(L, -2); |
| 3936 | |
| 3937 | Scene* scene = GuiScriptInstance_Check(L); |
| 3938 | dmGui::Result result; |
| 3939 | if (!lua_isnil(L, 1)) |
| 3940 | { |
| 3941 | dmGui::HNode hnode; |
| 3942 | InternalNode* root = LuaCheckNodeInternal(L, 1, &hnode); |
| 3943 | dmGui::HNode out_node; |
| 3944 | result = CloneNodeToTable(L, scene, root, &out_node); |
| 3945 | if (result == dmGui::RESULT_OK) |
| 3946 | { |
| 3947 | dmGui::HNode parent = INVALID_HANDLE; |
| 3948 | if (root->m_ParentIndex != INVALID_INDEX) |
| 3949 | { |
| 3950 | parent = GetNodeHandle(&scene->m_Nodes[root->m_ParentIndex]); |
| 3951 | } |
| 3952 | dmGui::SetNodeParent(scene, out_node, parent, false); |
| 3953 | } |
| 3954 | } |
| 3955 | else |
| 3956 | { |
| 3957 | result = CloneNodeListToTable(L, scene, scene->m_RenderHead, INVALID_HANDLE); |
| 3958 | } |
| 3959 | |
| 3960 | switch (result) |
| 3961 | { |
| 3962 | case dmGui::RESULT_OUT_OF_RESOURCES: |
| 3963 | lua_pop(L, 1); |
| 3964 | return luaL_error(L, "Not enough resources to clone the node tree"); |
| 3965 | case dmGui::RESULT_OK: |
| 3966 | assert(top + 1 == lua_gettop(L)); |
| 3967 | return 1; |
| 3968 | default: |
| 3969 | lua_pop(L, 1); |
| 3970 | return luaL_error(L, "An unexpected error occurred"); |
| 3971 | } |
| 3972 | } |
| 3973 | |
| 3974 | static void PushNodeListToTable(lua_State* L, dmGui::HScene scene, uint16_t start_index); |
| 3975 |
nothing calls this directly
no test coverage detected