sets a named property of the specified game object or component, or a material constant * * @name go.set * @param url [type:string|hash|url] url of the game object or component having the property * @param property [type:string|hash] id of the property to set * @param value [type:number|boolean|hash|url|vector3|vector4|quaternion|resource] the value to set * @param [o
| 766 | * go.set("#my_component", "some_property", some_value, { keys = { "root", "child_node" } }) |
| 767 | */ |
| 768 | int Script_Set(lua_State* L) |
| 769 | { |
| 770 | DM_LUA_STACK_CHECK(L, 0); |
| 771 | |
| 772 | DM_HASH_REVERSE_MEM(hash_ctx, 256); |
| 773 | ScriptInstance* i = ScriptInstance_Check(L); |
| 774 | Instance* instance = i->m_Instance; |
| 775 | dmMessage::URL sender; |
| 776 | dmScript::GetURL(L, &sender); |
| 777 | dmMessage::URL target; |
| 778 | dmScript::ResolveURL(L, 1, &target, &sender); |
| 779 | if (target.m_Socket != dmGameObject::GetMessageSocket(i->m_Instance->m_Collection->m_HCollection)) |
| 780 | { |
| 781 | luaL_error(L, "go.set can only access instances within the same collection."); |
| 782 | } |
| 783 | dmhash_t property_id = 0; |
| 784 | |
| 785 | if (lua_isstring(L, 2)) |
| 786 | { |
| 787 | property_id = dmHashString64(lua_tostring(L, 2)); |
| 788 | } |
| 789 | else |
| 790 | { |
| 791 | property_id = dmScript::CheckHash(L, 2); |
| 792 | } |
| 793 | |
| 794 | dmGameObject::HInstance target_instance = dmGameObject::GetInstanceFromIdentifier(dmGameObject::GetCollection(instance), target.m_Path); |
| 795 | if (target_instance == 0) |
| 796 | { |
| 797 | return luaL_error(L, "could not find any instance with id '%s'.", dmHashReverseSafe64Alloc(&hash_ctx, target.m_Path)); |
| 798 | } |
| 799 | |
| 800 | LuaToPropertyOptionsResult options_result = {}; |
| 801 | |
| 802 | if (lua_gettop(L) > 3) |
| 803 | { |
| 804 | LuaToPropertyOptions(L, 4, &options_result); |
| 805 | } |
| 806 | |
| 807 | if (lua_istable(L, 3)) |
| 808 | { |
| 809 | lua_pushvalue(L, 3); |
| 810 | lua_pushnil(L); |
| 811 | while (lua_next(L, -2) != 0) |
| 812 | { |
| 813 | if (!lua_isnumber(L, -2)) |
| 814 | { |
| 815 | return luaL_error(L, "Trying to set property value '%s' as array with a non-integer key.", dmHashReverseSafe64Alloc(&hash_ctx, property_id)); |
| 816 | } |
| 817 | |
| 818 | int32_t table_index_lua = lua_tonumber(L, -2); |
| 819 | |
| 820 | if (table_index_lua < 1) |
| 821 | { |
| 822 | return luaL_error(L, "Trying to set property value '%s' as array with a negative key (%d) is not permitted.", dmHashReverseSafe64Alloc(&hash_ctx, property_id), table_index_lua); |
| 823 | } |
| 824 | |
| 825 | dmGameObject::PropertyVar property_var; |
nothing calls this directly
no test coverage detected