MCPcopy Create free account
hub / github.com/MergHQ/CRYENGINE / SetValueAny

Method SetValueAny

Code/CryEngine/CryScriptSystem/ScriptTable.cpp:135–189  ·  view source on GitHub ↗

/////////////////////////////////////////////////////////////////////

Source from the content-addressed store, hash-verified

133
134//////////////////////////////////////////////////////////////////////////
135void CScriptTable::SetValueAny(const char* sKey, const ScriptAnyValue& any, bool bChain)
136{
137 CHECK_STACK(L);
138 int top = lua_gettop(L);
139
140 ScriptAnyValue oldValue;
141 if (top && lua_getmetatable(L, -1)) // if there is no metatable nothing is pushed
142 {
143 lua_pop(L, 1); // pop the metatable - we only care that it exists, not about the value
144 if (GetValueAny(sKey, oldValue, bChain) && oldValue == any)
145 return;
146 }
147
148 if (!bChain)
149 PushRef();
150
151 assert(sKey);
152 size_t len = strlen(sKey);
153
154 if (any.type == ANY_TVECTOR)
155 {
156 // Check if we can reuse Vec3 value already in the table.
157 lua_pushlstring(L, sKey, len);
158 lua_gettable(L, -2);
159 int luatype = lua_type(L, -1);
160 if (luatype == LUA_TTABLE)
161 {
162 lua_pushlstring(L, "x", 1);
163 lua_gettable(L, -2);
164 bool bXIsNumber = lua_isnumber(L, -1) != 0;
165 lua_pop(L, 1); // pop x value.
166 if (bXIsNumber)
167 {
168 // Assume its a vector, just fill it with new vector values.
169 lua_pushlstring(L, "x", 1);
170 lua_pushnumber(L, any.vec3.x);
171 lua_settable(L, -3);
172 lua_pushlstring(L, "y", 1);
173 lua_pushnumber(L, any.vec3.y);
174 lua_settable(L, -3);
175 lua_pushlstring(L, "z", 1);
176 lua_pushnumber(L, any.vec3.z);
177 lua_settable(L, -3);
178
179 lua_settop(L, top);
180 return;
181 }
182 }
183 lua_pop(L, 1); // pop key value.
184 }
185 lua_pushlstring(L, sKey, len);
186 m_pSS->PushAny(any);
187 lua_settable(L, -3);
188 lua_settop(L, top);
189}
190
191//////////////////////////////////////////////////////////////////////////
192bool CScriptTable::GetValueAny(const char* sKey, ScriptAnyValue& any, bool bChain)

Callers 8

AddSynchedTableMethod · 0.80
OnInitializeMethod · 0.80
ReadScriptMethod · 0.80
ReadScriptMethod · 0.80
MergeTableMethod · 0.80
SpawnMethod · 0.80

Calls 2

strlenFunction · 0.85
PushAnyMethod · 0.80

Tested by

no test coverage detected