Add function map
.
This commit is contained in:
@@ -77,11 +77,15 @@ namespace Cryville.Crtr {
|
||||
}
|
||||
static readonly int _op_sep = IdentifierManager.Shared.Request(",");
|
||||
static readonly int _func_int_map = IdentifierManager.Shared.Request("int_map");
|
||||
static readonly int _func_map = IdentifierManager.Shared.Request("map");
|
||||
protected override PdtOperator GetOperator(PdtOperatorSignature sig) {
|
||||
PdtOperator result;
|
||||
if (_shortops.TryGetValue(sig, out result)) {
|
||||
return result;
|
||||
}
|
||||
else if (_ctxops.TryGetValue(sig.Name, out result)) {
|
||||
return result;
|
||||
}
|
||||
else if (sig.Name == _op_sep) {
|
||||
result = new op_arr(sig.ParamCount);
|
||||
_shortops.Add(new PdtOperatorSignature(_op_sep, sig.ParamCount), result);
|
||||
@@ -92,7 +96,9 @@ namespace Cryville.Crtr {
|
||||
_shortops.Add(new PdtOperatorSignature(_func_int_map, sig.ParamCount), result);
|
||||
return result;
|
||||
}
|
||||
else if (_ctxops.TryGetValue(sig.Name, out result)) {
|
||||
else if (sig.Name == _func_map) {
|
||||
result = new func_map(sig.ParamCount);
|
||||
_shortops.Add(new PdtOperatorSignature(_func_map, sig.ParamCount), result);
|
||||
return result;
|
||||
}
|
||||
else throw new KeyNotFoundException(string.Format("Undefined operator {0}", sig));
|
||||
@@ -388,6 +394,19 @@ namespace Cryville.Crtr {
|
||||
.SetNumber(GetOperand(0).Equals(GetOperand(1)) ? 1 : 0);
|
||||
}
|
||||
}
|
||||
class func_map : PdtOperator {
|
||||
public func_map(int pc) : base(pc) {
|
||||
if (pc < 2) throw new ArgumentOutOfRangeException("Too few parameters for map");
|
||||
}
|
||||
protected override unsafe void Execute() {
|
||||
var value = GetOperand(0).AsNumber();
|
||||
var index = (int)value;
|
||||
if (index < 0 || index >= LoadedOperandCount - 1) index = 0;
|
||||
var hit = GetOperand(index + 1);
|
||||
var ret = GetReturnFrame(hit.Type, hit.Length);
|
||||
hit.CopyTo(ret);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
#region Contextual Functions
|
||||
class func_screen_edge : PdtOperator {
|
||||
|
Reference in New Issue
Block a user