/// <summary> /// Checks if the type is a specific userdata type, and returns it or throws. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="funcName">Name of the function.</param> /// <param name="argNum">The argument number.</param> /// <param name="flags">The flags.</param> /// <returns></returns> public T CheckUserDataType <T>(string funcName, int argNum = -1, TypeValidationFlags flags = TypeValidationFlags.Default) { DynValue v = this.CheckType(funcName, DataType.UserData, argNum, flags); bool allowNil = ((int)(flags & TypeValidationFlags.AllowNil) != 0); if (v.IsNil()) { return(default(T)); } object o = v.UserData.Object; if (o != null && o is T) { return((T)o); } throw ScriptRuntimeException.BadArgumentUserData(argNum, funcName, typeof(T), o, allowNil); }
/// <summary> /// Sets the value associated to the specified key. /// </summary> /// <param name="key">The key.</param> /// <param name="value">The value.</param> public void Set(string key, DynValue value) { if (!_isAlive) { throw new InvalidOperationException(string.Format("Attempting to Set on dead Table")); } if (key == null) { throw ScriptRuntimeException.TableIndexIsNil(); } this.CheckScriptOwnership(value); if (m_StringMap == null) { m_StringMap = new LinkedListIndex <string, TablePair>(ValuesList); } PerformTableSet(m_StringMap, key, DynValue.NewString(key), value, false, -1); }
/// <summary> /// Sets the value associated with the specified key. /// </summary> /// <param name="key">The key.</param> /// <param name="value">The value.</param> public void Set(object key, DynValue value) { if (key == null) { throw ScriptRuntimeException.TableIndexIsNil(); } if (key is string) { Set((string)key, value); } else if (key is int) { Set((int)key, value); } else { Set(DynValue.FromObject(OwnerScript, key), value); } }
/// <summary> /// Resumes the coroutine. /// </summary> /// <param name="context">The ScriptExecutionContext.</param> /// <param name="args">The arguments.</param> /// <returns></returns> public DynValue Resume(ScriptExecutionContext context, params DynValue[] args) { this.CheckScriptOwnership(context); this.CheckScriptOwnership(args); if (Type == CoroutineType.Coroutine) { return(m_Processor.Coroutine_Resume(args)); } else if (Type == CoroutineType.ClrCallback) { DynValue ret = m_ClrCallback.Invoke(context, args); MarkClrCallbackAsDead(); return(ret); } else { throw ScriptRuntimeException.CannotResumeNotSuspended(CoroutineState.Dead); } }
/// <summary> /// Sets the value associated to the specified key. /// </summary> /// <param name="key">The key.</param> /// <param name="value">The value.</param> public void Set(DynValue key, DynValue value) { if (key.IsNilOrNan()) { if (key.IsNil()) { throw ScriptRuntimeException.TableIndexIsNil(); } else { throw ScriptRuntimeException.TableIndexIsNaN(); } } if (key.Type == DataType.String) { Set(key.String, value); return; } if (key.Type == DataType.Number) { int idx = GetIntegralKey(key.Number); if (idx >= (OwnerScript.Options.ZeroIndexTables ? 0 : 1)) { Set(idx, value); return; } } this.CheckScriptOwnership(key); this.CheckScriptOwnership(value); PerformTableSet(m_ValueMap, key, key, value, false, -1); }
/// <summary> /// Sets the value associated with the specified key. /// </summary> /// <param name="key">The key.</param> /// <param name="value">The value.</param> public void Set(object key, DynValue value) { if (!_isAlive) { throw new InvalidOperationException(string.Format("Attempting to Set on dead Table")); } if (key == null) { throw ScriptRuntimeException.TableIndexIsNil(); } if (key is string) { Set((string)key, value); } else if (key is int) { Set((int)key, value); } else { Set(DynValue.FromObject(OwnerScript, key), value); } }
/// <summary> /// Sets the value associated to the specified key. /// </summary> /// <param name="key">The key.</param> /// <param name="value">The value.</param> public void Set(DynValue key, DynValue value) { if (key.IsNilOrNan()) { if (key.IsNil()) { throw ScriptRuntimeException.TableIndexIsNil(); } else { throw ScriptRuntimeException.TableIndexIsNaN(); } } if (key.Type == DataType.String) { Set(key.String, value); return; } if (key.Type == DataType.Number) { int idx = GetIntegralKey(key.Number); if (idx > 0) { Set(idx, value); return; } } CheckValueOwner(key); CheckValueOwner(value); PerformTableSet(m_ValueMap, key, key, value, false); }
/// <summary> /// Initializes a new instance of the <see cref="ScriptRuntimeException"/> class. /// </summary> /// <param name="ex">The ex.</param> public ScriptRuntimeException(ScriptRuntimeException ex) : base(ex, ex.DecoratedMessage) { this.DecoratedMessage = Message; this.DoNotDecorateMessage = true; }
/// <summary> /// Performs a message decoration before unwinding after an error. To be used in the implementation of xpcall like functions. /// </summary> /// <param name="messageHandler">The message handler.</param> /// <param name="exception">The exception.</param> public void PerformMessageDecorationBeforeUnwind(DynValue messageHandler, ScriptRuntimeException exception) { if (messageHandler != null) exception.DecoratedMessage = m_Processor.PerformMessageDecorationBeforeUnwind(messageHandler, exception.Message, CallingLocation); else exception.DecoratedMessage = exception.Message; }
static void HandleScriptError(ScriptRuntimeException ex) { string errormsg = ex.DecoratedMessage + "\nStack Trace :\n"; var stack = ex.CallStack; int count = stack.Count; for (int i = 0; i < count; i++ ) { var loc = stack[i].Location; errormsg += string.Format(" {0}\n", loc.FormatLocation(s_instance.m_engine)); } Debug.LogError(errormsg); }
public bool SignalRuntimeException(ScriptRuntimeException ex) { SendMessage(string.Format("Error: {0}", ex.DecoratedMessage)); m_RequestPause = m_ErrorRegEx.IsMatch(ex.Message); return IsPauseRequested(); }
public bool SignalRuntimeException(ScriptRuntimeException ex) { Console_WriteLine("Error: {0}", ex.DecoratedMessage); return true; }
public void OnException(ScriptRuntimeException ex) { SendText("runtime error : {0}", ex.DecoratedMessage); }
bool IDebugger.SignalRuntimeException(ScriptRuntimeException ex) { lock (m_Lock) if (Client == null) return false; Client.OnException(ex); PauseRequested = ErrorRegex.IsMatch(ex.Message); return PauseRequested; }
public bool SignalRuntimeException(ScriptRuntimeException ex) { return false; }