| 1027 | } |
| 1028 | |
| 1029 | PropertyResult CompScriptSetProperty(const ComponentSetPropertyParams& params) |
| 1030 | { |
| 1031 | HScriptInstance script_instance = (HScriptInstance)*params.m_UserData; |
| 1032 | |
| 1033 | dmPropertiesDDF::PropertyDeclarations* declarations = &script_instance->m_Script->m_LuaModule->m_Properties; |
| 1034 | PropertyType type = PROPERTY_TYPE_NUMBER; |
| 1035 | const char* property_name = 0x0; |
| 1036 | dmhash_t* element_ids = 0x0; |
| 1037 | bool is_element = false; |
| 1038 | uint32_t element_index = 0; |
| 1039 | if (!FindPropertyName(declarations, params.m_PropertyId, &property_name, &type, &element_ids, &is_element, &element_index)) |
| 1040 | return PROPERTY_RESULT_NOT_FOUND; |
| 1041 | |
| 1042 | lua_State* L = GetLuaState(script_instance); |
| 1043 | |
| 1044 | int top = lua_gettop(L); |
| 1045 | (void)top; |
| 1046 | |
| 1047 | // Only push the script instance if it's not present already |
| 1048 | bool pushed_instance = false; |
| 1049 | dmScript::GetInstance(L); |
| 1050 | pushed_instance = lua_isnil(L, -1); |
| 1051 | lua_pop(L, 1); |
| 1052 | if (pushed_instance) |
| 1053 | { |
| 1054 | lua_rawgeti(L, LUA_REGISTRYINDEX, script_instance->m_InstanceReference); |
| 1055 | dmScript::SetInstance(L); |
| 1056 | } |
| 1057 | |
| 1058 | lua_rawgeti(L, LUA_REGISTRYINDEX, script_instance->m_ScriptDataReference); |
| 1059 | |
| 1060 | PropertyVar var = params.m_Value; |
| 1061 | if (is_element) |
| 1062 | { |
| 1063 | PropertyResult result = PROPERTY_RESULT_NOT_FOUND; |
| 1064 | lua_pushstring(L, property_name); |
| 1065 | lua_rawget(L, -2); |
| 1066 | if (!lua_isnil(L, -1)) |
| 1067 | { |
| 1068 | result = LuaToVar(L, -1, var); |
| 1069 | if (result == PROPERTY_RESULT_OK) |
| 1070 | { |
| 1071 | var.m_V4[element_index] = (float) params.m_Value.m_Number; |
| 1072 | } |
| 1073 | } |
| 1074 | |
| 1075 | lua_pop(L, 1); |
| 1076 | } |
| 1077 | lua_pushstring(L, property_name); |
| 1078 | LuaPushVar(L, var); |
| 1079 | lua_rawset(L, -3); |
| 1080 | |
| 1081 | lua_pop(L, 1); |
| 1082 | |
| 1083 | if (pushed_instance) |
| 1084 | { |
| 1085 | lua_pushnil(L); |
| 1086 | dmScript::SetInstance(L); |
nothing calls this directly
no test coverage detected