private Encapsulation.Structure InvokeDelegate(Lexicon map, string suffixName, params Encapsulation.Structure[] parameters) { ISuffixResult lengthResult = map.GetSuffix(suffixName); Assert.IsNotNull(lengthResult); if (!lengthResult.HasValue) { var delegateResult = lengthResult as DelegateSuffixResult; if (delegateResult != null) { cpu.PushArgumentStack(null); // fake delegate info cpu.PushArgumentStack(new KOSArgMarkerType()); foreach (var param in parameters) { cpu.PushArgumentStack(param); } delegateResult.Invoke(cpu); return(delegateResult.Value); } } return(lengthResult.Value); }
public object VesselShortcutGetter(string name) { ISuffixResult suffix = ship.GetSuffix(name); if (!suffix.HasValue) { suffix.Invoke(sharedObj.Cpu); } return(suffix.Value); }
string GetItemString(Structure item) { if (item.HasSuffix(optSuffix)) { ISuffixResult v = item.GetSuffix(optSuffix); if (v.HasValue) { return(v.Value.ToString()); } } return(item.ToString()); }
// Try to get the suffix the normal way that all structures do, but if // that fails, then try to get the value in the lexicon who's key is // this suffix name. (This implements using keys with the "colon" suffix // syntax for issue #2551.) public override ISuffixResult GetSuffix(string suffixName, bool failOkay = false) { ISuffixResult baseResult = base.GetSuffix(suffixName, true); if (baseResult != null) { return(baseResult); } // If the above fails, but this suffix IS the name of a key in the // dictionary, then try to use the key-suffix we made earlier // (or make a new one and use it now) // --------------------------------------------------------------- StringValue suffixAsStruct = new StringValue(suffixName); if (internalDictionary.ContainsKey(suffixAsStruct)) // even if keySuffixes has the value, it doesn't count if the key isn't there anymore. { SetSuffix <Structure> theSuffix; if (keySuffixes.TryGetValue(suffixAsStruct, out theSuffix)) { return(theSuffix.Get()); } else // make a new suffix then since this is the first time it got mentioned this way: { theSuffix = new SetSuffix <Structure>(() => internalDictionary[suffixAsStruct], value => internalDictionary[suffixAsStruct] = value); keySuffixes.Add(suffixAsStruct, theSuffix); return(theSuffix.Get()); } } else { // This will error out, but we may as well also remove this key // from the list of suffixes: keySuffixes.Remove(suffixAsStruct); if (failOkay) { return(null); } else { throw new KOSSuffixUseException("get", suffixName, this); } } }
private Encapsulation.Structure InvokeDelegate(ISuffixed map, string suffixName, params Encapsulation.Structure[] parameters) { ISuffixResult lengthResult = map.GetSuffix(suffixName); Assert.IsNotNull(lengthResult); if (!lengthResult.HasValue) { var delegateResult = lengthResult as DelegateSuffixResult; if (delegateResult != null) { var temp = delegateResult.Del.DynamicInvoke(parameters); return(temp as Encapsulation.Structure); } } return(lengthResult.Value); }