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
| 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 | * |
nothing calls this directly
no test coverage detected