MCPcopy Create free account
hub / github.com/BohemiaInteractive/CWR / ListSet

Function ListSet

engine/Evaluator/express.cpp:678–721  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

676}
677
678static GameValue ListSet(const GameState* state, GameValuePar oper1, GameValuePar oper2)
679{
680 const GameArrayType& array = oper1;
681 const GameArrayType& arg = oper2;
682 if (arg.Size() != 2)
683 {
684 state->SetError(EvalDim, array.Size(), 2);
685 return NOTHING;
686 }
687 if (arg[0].GetType() != GameScalar)
688 {
689 state->TypeError(GameScalar, arg[0].GetType());
690 return NOTHING;
691 }
692
693 float index = arg[0];
694 const GameValue& value = arg[1];
695 int sel = toInt(index);
696 if (sel < 0)
697 {
698 state->SetError(EvalDivZero);
699 return NOTHING;
700 }
701
702 if (oper1.GetReadOnly())
703 {
704 state->SetError(EvalBadVar);
705 return NOTHING;
706 }
707 GameArrayType& arrayNC = const_cast<GameArrayType&>(array);
708 arrayNC.Access(sel); // grows the array if needed
709 // storing an array that contains this array would create a recursive
710 // structure, which later crashes; reject it instead
711 if (CheckArrayInValue(array, value))
712 {
713 Fail("Recursive array");
714 state->SetError(EvalDim);
715 return NOTHING;
716 }
717
718 arrayNC[sel] = value;
719
720 return NOTHING;
721}
722
723static GameValue StringCall(const GameState* state, GameValuePar oper1, GameValuePar oper2)
724{

Callers

nothing calls this directly

Calls 8

CheckArrayInValueFunction · 0.85
TypeErrorMethod · 0.80
AccessMethod · 0.80
toIntFunction · 0.50
SizeMethod · 0.45
SetErrorMethod · 0.45
GetTypeMethod · 0.45
GetReadOnlyMethod · 0.45

Tested by

no test coverage detected