public void Start() { lock (_threadCountKey) { int startCount = (int)_context.LanguageContext.GetOrCreateModuleState <object>(_threadCountKey, () => 0); _context.LanguageContext.SetModuleState(_threadCountKey, startCount + 1); } try { #pragma warning disable 618 // TODO: obsolete if (_kwargs != null) { PythonOps.CallWithArgsTupleAndKeywordDictAndContext(_context, _func, ArrayUtils.EmptyObjects, ArrayUtils.EmptyStrings, _args, _kwargs); } else { PythonOps.CallWithArgsTuple(_func, ArrayUtils.EmptyObjects, _args); } #pragma warning restore 618 } catch (SystemExitException) { // ignore and quit } catch (Exception e) { PythonOps.PrintWithDest(_context, PythonContext.GetContext(_context).SystemStandardError, "Unhandled exception on thread"); string result = _context.LanguageContext.FormatException(e); PythonOps.PrintWithDest(_context, PythonContext.GetContext(_context).SystemStandardError, result); } finally { lock (_threadCountKey) { int curCount = (int)_context.LanguageContext.GetModuleState(_threadCountKey); _context.LanguageContext.SetModuleState(_threadCountKey, curCount - 1); } } }
public static object call_function(CodeContext context, IntPtr address, PythonTuple args) { CFuncPtrType funcType = GetFunctionType(context, FUNCFLAG_STDCALL); _CFuncPtr func = (_CFuncPtr)funcType.CreateInstance(context, address); return(PythonOps.CallWithArgsTuple(func, new object[0], args)); }
public void RegistHandle(CodeContext context, object function) { try { var obj = PythonOps.CallWithArgsTuple(function, ArrayUtils.EmptyObjects, ""); if (obj != null) { SetInner(context, obj); } } catch (SystemExitException e) { } catch (Exception e) { } }
public void Start() { try { if (_kwargs != null) { PythonOps.CallWithArgsTupleAndKeywordDictAndContext(_context, _func, ArrayUtils.EmptyObjects, ArrayUtils.EmptyStrings, _args, _kwargs); } else { PythonOps.CallWithArgsTuple(_func, ArrayUtils.EmptyObjects, _args); } } catch (SystemExitException) { // ignore and quit } catch (Exception e) { PythonOps.PrintWithDest(_context, PythonContext.GetContext(_context).SystemStandardError, "Unhandled exception on thread"); string result = _context.LanguageContext.FormatException(e); PythonOps.PrintWithDest(_context, PythonContext.GetContext(_context).SystemStandardError, result); } }
internal static System.Exception CreateThrowableForRaise(CodeContext /*!*/ context, PythonType /*!*/ type, object value, BaseException cause) { object pyEx; if (PythonOps.IsInstance(value, type)) { pyEx = value; } else if (value is PythonTuple) { pyEx = PythonOps.CallWithArgsTuple(type, ArrayUtils.EmptyObjects, value); } else if (value != null) { pyEx = PythonCalls.Call(context, type, value); } else { pyEx = PythonCalls.Call(context, type); } if (pyEx is BaseException) { var contextException = PythonOps.GetRawContextException(); // If we have a context-exception or no context/cause return the existing, or a new exception if (cause != null) { return(((BaseException)pyEx).CreateClrExceptionWithCause(cause, null)); } else if (contextException == null) { return(((BaseException)pyEx).GetClrException()); } else if (context != null) { // Generate new CLR-Exception and return it return(((BaseException)pyEx).CreateClrExceptionWithCause(null, contextException)); } } throw PythonOps.TypeError($"calling {PythonOps.ToString(type)} should have returned an instance of BaseException, not {PythonOps.ToString(DynamicHelpers.GetPythonType(pyEx))}"); }
internal static object Add(CodeContext context, GameObject parent, object function, PythonTuple args, object kwargs) { try { #pragma warning disable 618 // TODO: obsolete object result; if (kwargs != null) { result = PythonOps.CallWithArgsTupleAndKeywordDictAndContext(context, function, ArrayUtils.EmptyObjects, ArrayUtils.EmptyStrings, args, kwargs); } else { result = PythonOps.CallWithArgsTuple(function, ArrayUtils.EmptyObjects, args); } #pragma warning restore 618 if (result != null) { var ex = parent.AddComponent <GuiBehavior>(); if (ex != null) { ex.SetInner(context, result); return(ex); //return PythonTuple.MakeTuple(obj, ex); } } } catch (SystemExitException) { // ignore and quit } catch (Exception e) { PythonOps.PrintWithDest(context, PythonContext.GetContext(context).SystemStandardError, "Unhandled exception on coroutine"); var exstr = context.LanguageContext.FormatException(e); PythonOps.PrintWithDest(context, PythonContext.GetContext(context).SystemStandardError, exstr); } return(null); }