/usr/src/castle-game-engine-5.2.0/castlescript/castlescriptarrays_implement.inc is in castle-game-engine-src 5.2.0-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 | {
Copyright 2008-2014 Michalis Kamburelis.
This file is part of "Castle Game Engine".
"Castle Game Engine" is free software; see the file COPYING.txt,
included in this distribution, for details about the copyright.
"Castle Game Engine" is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
----------------------------------------------------------------------------
}
constructor TCasScriptXxxArray.Create(const AWriteable: boolean; const AValue: TXxxList);
begin
Create(AWriteable);
Value := AValue;
end;
constructor TCasScriptXxxArray.Create(const AWriteable: boolean);
begin
inherited;
FValue := TXxxList.Create;
end;
destructor TCasScriptXxxArray.Destroy;
begin
FreeAndNil(FValue);
inherited;
end;
procedure TCasScriptXxxArray.SetValue(const AValue: TXxxList);
begin
FValue.Assign(AValue);
ValueAssigned := true;
end;
procedure TCasScriptXxxArray.AssignValue(Source: TCasScriptValue);
begin
if Source is TCasScriptXxxArray then
Value := TCasScriptXxxArray(Source).Value else
raise ECasScriptAssignError.CreateFmt('Assignment from %s to %s not possible', [Source.ClassName, ClassName]);
end;
class procedure TCasScriptXxxArray.HandleArrayFun(AFunction: TCasScriptFunction; const Arguments: array of TCasScriptValue; var AResult: TCasScriptValue; var ParentOfResult: boolean);
var
I: Integer;
Arr: TXxxList;
begin
CreateValueIfNeeded(AResult, ParentOfResult, TCasScriptXxxArray);
Arr := TCasScriptXxxArray(AResult).Value;
Arr.Count := Length(Arguments);
for I := 0 to Length(Arguments) - 1 do
Arr.L[I] := TCasScriptXxxElement(Arguments[I]).Value;
TCasScriptXxxArray(AResult).ValueAssigned := true;
end;
class procedure TCasScriptXxxArray.HandleArrayGetCount(AFunction: TCasScriptFunction; const Arguments: array of TCasScriptValue; var AResult: TCasScriptValue; var ParentOfResult: boolean);
begin
CreateValueIfNeeded(AResult, ParentOfResult, TCasScriptInteger);
TCasScriptInteger(AResult).Value :=
TCasScriptXxxArray(Arguments[0]).FValue.Count;
end;
class procedure TCasScriptXxxArray.HandleArraySetCount(AFunction: TCasScriptFunction; const Arguments: array of TCasScriptValue; var AResult: TCasScriptValue; var ParentOfResult: boolean);
var
NewCount: Int64;
begin
if ParentOfResult then
AResult.FreeByParentExpression;
AResult := nil;
ParentOfResult := false;
NewCount := TCasScriptInteger(Arguments[1]).Value;
if NewCount < 0 then
raise ECasScriptError.CreateFmt('Invalid count %d for array_set_count (should be non-negative)',
[NewCount]);
TCasScriptXxxArray(Arguments[0]).FValue.Count := NewCount;
TCasScriptXxxArray(Arguments[0]).ValueAssigned := true;
AResult := Arguments[0];
end;
class procedure TCasScriptXxxArray.HandleArrayGet(AFunction: TCasScriptFunction; const Arguments: array of TCasScriptValue; var AResult: TCasScriptValue; var ParentOfResult: boolean);
var
Index: Integer;
Arr: TXxxList;
begin
CreateValueIfNeeded(AResult, ParentOfResult, TCasScriptXxxElement);
Arr := TCasScriptXxxArray(Arguments[0]).Value;
Index := TCasScriptInteger(Arguments[1]).Value;
if not Between(Index, 0, Arr.Count - 1) then
raise ECasScriptError.CreateFmt('Invalid index %d for array_get, array count is %d',
[Index, Arr.Count]);
TCasScriptXxxElement(AResult).Value := Arr.L[Index];
end;
class procedure TCasScriptXxxArray.HandleArraySet(AFunction: TCasScriptFunction; const Arguments: array of TCasScriptValue; var AResult: TCasScriptValue; var ParentOfResult: boolean);
var
Index: Integer;
Arr: TXxxList;
begin
if ParentOfResult then
AResult.FreeByParentExpression;
AResult := nil;
ParentOfResult := false;
Arr := TCasScriptXxxArray(Arguments[0]).Value;
Index := TCasScriptInteger(Arguments[1]).Value;
if not Between(Index, 0, Arr.Count - 1) then
raise ECasScriptError.CreateFmt('Invalid index %d for array_set, array count is %d',
[Index, Arr.Count]);
Arr.L[Index] := TCasScriptXxxElement(Arguments[2]).Value;
TCasScriptXxxArray(Arguments[0]).ValueAssigned := true;
AResult := Arguments[0];
end;
class procedure TCasScriptXxxArray.HandleAdd(AFunction: TCasScriptFunction; const Arguments: array of TCasScriptValue; var AResult: TCasScriptValue; var ParentOfResult: boolean);
var
I: Integer;
Arr: TXxxList;
begin
CreateValueIfNeeded(AResult, ParentOfResult, TCasScriptXxxArray);
Arr := TCasScriptXxxArray(AResult).Value;
{ initially Arr is empty. This is needed to set explicitly,
since CreateValueIfNeeded could left previous AResult }
Arr.Clear;
for I := 0 to Length(Arguments) - 1 do
Arr.AddList(TCasScriptXxxArray(Arguments[I]).Value);
TCasScriptXxxArray(AResult).ValueAssigned := true;
end;
procedure RegisterXxxFunctions;
begin
FunctionHandlers.RegisterHandler(@TCasScriptXxxArray(nil).HandleArrayFun, TCasScriptXxxArrayFun, [TCasScriptXxxElement], true);
FunctionHandlers.RegisterHandler(@TCasScriptXxxArray(nil).HandleArrayGetCount, TCasScriptArrayGetCount, [TCasScriptXxxArray], false);
FunctionHandlers.RegisterHandler(@TCasScriptXxxArray(nil).HandleArraySetCount, TCasScriptArraySetCount, [TCasScriptXxxArray, TCasScriptInteger], false);
FunctionHandlers.RegisterHandler(@TCasScriptXxxArray(nil).HandleArrayGet, TCasScriptArrayGet, [TCasScriptXxxArray, TCasScriptInteger], false);
FunctionHandlers.RegisterHandler(@TCasScriptXxxArray(nil).HandleArraySet, TCasScriptArraySet, [TCasScriptXxxArray, TCasScriptInteger, TCasScriptXxxElement], false);
FunctionHandlers.RegisterHandler(@TCasScriptXxxArray(nil).HandleAdd, TCasScriptAdd, [TCasScriptXxxArray], true);
end;
|