Example #1
0
 /// <summary>
 /// Is a slot name valid.
 /// </summary>
 /// <param name="slotName">the name of the slot</param>
 /// <returns>whether a slot name is present in the object</returns>
 public bool HasSlot(string slotName)
 {
     using (var s = new ProtectedPointer(Engine, GetFunction <Rf_mkString>()(InternalString.NativeUtf8FromString(slotName))))
     {
         return(this.GetFunction <R_has_slot>()(this.DangerousGetHandle(), s));
     }
 }
Example #2
0
        private SymbolicExpression Parse(string statement, StringBuilder incompleteStatement, REnvironment environment = null)
        {
            incompleteStatement.Append(statement);
            var    s = GetFunction <Rf_mkString>()(InternalString.NativeUtf8FromString(incompleteStatement.ToString()));
            string errorStatement;

            using (new ProtectedPointer(this, s))
            {
                ParseStatus status;
                var         vector = new ExpressionVector(this, GetFunction <R_ParseVector>()(s, -1, out status, NilValue.DangerousGetHandle()));

                switch (status)
                {
                case ParseStatus.OK:
                    incompleteStatement.Clear();
                    if (vector.Length == 0)
                    {
                        return(null);
                    }
                    using (new ProtectedPointer(vector))
                    {
                        SymbolicExpression result;
                        if (!vector.First().TryEvaluate((environment == null) ? GlobalEnvironment : environment, out result))
                        {
                            throw new EvaluationException(LastErrorMessage);
                        }

                        if (AutoPrint && !result.IsInvalid && GetVisible())
                        {
                            GetFunction <Rf_PrintValue>()(result.DangerousGetHandle());
                        }
                        return(result);
                    }

                case ParseStatus.Incomplete:
                    return(null);

                case ParseStatus.Error:
                    // TODO: use LastErrorMessage if below is just a subset
                    var parseErrorMsg = this.GetAnsiString("R_ParseErrorMsg");
                    errorStatement = incompleteStatement.ToString();
                    incompleteStatement.Clear();
                    throw new ParseException(status, errorStatement, parseErrorMsg);

                default:
                    errorStatement = incompleteStatement.ToString();
                    incompleteStatement.Clear();
                    throw new ParseException(status, errorStatement, "");
                }
            }
        }
Example #3
0
 /// <summary>
 /// Gets/sets the value of a slot
 /// </summary>
 /// <param name="name"></param>
 /// <returns></returns>
 public SymbolicExpression this[string name]
 {
     get
     {
         checkSlotName(name);
         IntPtr slotValue;
         using (var s = new ProtectedPointer(Engine, GetFunction <Rf_mkString>()(InternalString.NativeUtf8FromString(name))))
         {
             slotValue = this.GetFunction <R_do_slot>()(this.DangerousGetHandle(), s);
         }
         return(new SymbolicExpression(Engine, slotValue));
     }
     set
     {
         checkSlotName(name);
         using (var s = new ProtectedPointer(Engine, GetFunction <Rf_mkString>()(InternalString.NativeUtf8FromString(name))))
         {
             using (new ProtectedPointer(this))
             {
                 this.GetFunction <R_do_slot_assign>()(this.DangerousGetHandle(), s, value.DangerousGetHandle());
             }
         }
     }
 }