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

Function LuaCloneTree

engine/gui/src/gui_script.cpp:3924–3972  ·  view source on GitHub ↗

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 */

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 12

lua_gettopFunction · 0.85
lua_createtableFunction · 0.85
lua_setfieldFunction · 0.85
lua_setmetatableFunction · 0.85
GuiScriptInstance_CheckFunction · 0.85
LuaCheckNodeInternalFunction · 0.85
CloneNodeToTableFunction · 0.85
CloneNodeListToTableFunction · 0.85
luaL_errorFunction · 0.85
GetNodeHandleFunction · 0.70
SetNodeParentFunction · 0.70
assertFunction · 0.50

Tested by

no test coverage detected