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

Function LuaGetNode

engine/gui/src/gui_script.cpp:491–527  ·  view source on GitHub ↗

gets the node with the specified id * * Retrieves the node with the specified id. * * @name gui.get_node * @param id [type:string|hash] id of the node to retrieve * @return instance [type:node] a new node instance * @examples * * Gets a node by id and change its color: * * ```lua * local node = gui.get_node("my_node") * local red = v

Source from the content-addressed store, hash-verified

489 * ```
490 */
491 static int LuaGetNode(lua_State* L)
492 {
493 int top = lua_gettop(L);
494 (void) top;
495
496 Scene* scene = GuiScriptInstance_Check(L);
497
498 HNode node = 0;
499 if (lua_isstring(L, 1))
500 {
501 const char* id = luaL_checkstring(L, 1);
502 node = GetNodeById(scene, id);
503 if (node == 0)
504 {
505 luaL_error(L, "No such node: %s", id);
506 }
507 }
508 else
509 {
510 dmhash_t id = dmScript::CheckHash(L, 1);
511 node = GetNodeById(scene, id);
512 if (node == 0)
513 {
514 luaL_error(L, "No such node: '%s'", dmHashReverseSafe64(id));
515 }
516 }
517
518 NodeProxy* node_proxy = (NodeProxy *)lua_newuserdata(L, sizeof(NodeProxy));
519 node_proxy->m_Scene = scene;
520 node_proxy->m_Node = node;
521 luaL_getmetatable(L, NODE_PROXY_TYPE_NAME);
522 lua_setmetatable(L, -2);
523
524 assert(top + 1 == lua_gettop(L));
525
526 return 1;
527 }
528
529 /*# gets the id of the specified node
530 *

Callers

nothing calls this directly

Calls 10

lua_gettopFunction · 0.85
GuiScriptInstance_CheckFunction · 0.85
lua_isstringFunction · 0.85
luaL_errorFunction · 0.85
CheckHashFunction · 0.85
dmHashReverseSafe64Function · 0.85
lua_newuserdataFunction · 0.85
lua_setmetatableFunction · 0.85
GetNodeByIdFunction · 0.70
assertFunction · 0.50

Tested by

no test coverage detected