Skip to main content

CurrentContext

Struct CurrentContext 

Source
pub struct CurrentContext<'a>(/* private fields */);
Expand description

The current ANE context, on which most APIs in this crate depend.

The lifetime is strictly tied to the function call stack.

§Invariant

During any context-related call, the current context is guaranteed to be valid, and its associated ExtensionContext object must not call dispose.

Violating this invariant may cause subsequent API calls to fail and lead to rapidly increasing complexity in error handling. This crate treats such situations as invalid state and does not attempt to recover from them.

Implementations§

Source§

impl<'a> CurrentContext<'a>

Source

pub fn ty(&self) -> Option<UCStr>

Returns the context type associated with the current context.

This corresponds to the contextType argument passed to ExtensionContext.createExtensionContext.

Returns None if that argument was null.

Source

pub fn data(&self) -> Option<&dyn Any>

Returns an immutable reference to the Context Data associated with the current context.

Context Data is user-defined data bound to the context, sharing the same lifetime as the context itself.

It can only be set via the first return value of ContextInitializer.

Source

pub fn data_mut(&mut self) -> Option<&mut dyn Any>

Returns a mutable reference to the Context Data associated with the current context.

Context Data is user-defined data bound to the context, sharing the same lifetime as the context itself.

It can only be set via the first return value of ContextInitializer.

Source

pub fn call_method( &mut self, name: &str, args: Option<&[Object<'a>]>, ) -> Result<Object<'a>, ContextError>

Calls a method associated with the current context.

Methods can only be set via the second return value of ContextInitializer.

Err=> ContextError::MethodsNotRegistered, ContextError::MethodNotFound;

Source

pub fn get_actionscript_data(&self) -> Object<'a>

Returns the ActionScript-side Context Data associated with the current context.

ExtensionContext.actionScriptData

Source

pub fn set_actionscript_data(&self, object: Object<'_>)

Sets the ActionScript-side Context Data associated with the current context.

ExtensionContext.actionScriptData

Source

pub unsafe fn cooperative_context_from_object( &self, context: Object<'a>, ) -> CooperativeContext<'a>

Returns the associated context from an ExtensionContext object.

§Safety

context must be another context constructed by the current extension via ContextInitializer. Otherwise, the invariants of CooperativeContext are violated, and its internal APIs for accessing native data will result in undefined behavior.

§Panic

Panics if context is not an ExtensionContext object, or if it is associated with the current context.

Source

pub fn foreign_context_from_object( &self, context: Object<'a>, ) -> ForeignContext<'a>

Returns the associated context from an ExtensionContext object.

§Panic

Panics if context is not an ExtensionContext object, or if it is associated with the current context.

Source§

impl<'a> CurrentContext<'a>

Source

pub unsafe fn with<F, R>(ctx: &'a FREContext, f: F) -> R
where F: FnOnce(&CurrentContext<'a>) -> R, R: 'a,

A wrapper used by FREContextInitializer, FREContextFinalizer, and FREFunction that provides a safe stack-level execution environment.

In typical usage of this crate, this function should not be called directly.

§Safety

While all operations performed within this function are safe at the stack level, calling this function itself is unsafe and requires that all input arguments are valid. In particular, this function assumes it is invoked directly with arguments provided by the Flash runtime.

Violating these assumptions may lead to undefined behavior.

Source

pub unsafe fn with_context_initializer<F>( ext_data: FREData, ctx_type: FREStr, ctx: &'a FREContext, num_funcs_to_set: *mut u32, funcs_to_set: *mut *const FRENamedFunction, f: F, )
where F: FnOnce(&CurrentContext<'a>) -> (Option<Box<dyn Any>>, FunctionSet),

A wrapper around FREContextInitializer that provides a safe stack-level execution environment for context initialization.

In typical usage of this crate, this function should not be called directly.

§Safety

While all operations performed within this function are safe at the stack level, calling this function itself is unsafe and requires the following conditions:

  • The native data associated with Context must not be accessed or managed by external code.
  • This function will construct a ContextRegistry and assign it as the native data. The constructed ContextRegistry must be properly disposed in FREContextFinalizer to ensure its lifecycle is correctly terminated.
  • This function assumes it is invoked directly with arguments provided by the Flash runtime, meaning all arguments must be valid and consistent.

Violating these assumptions may lead to undefined behavior.

Source

pub unsafe fn with_method<F, R>( ctx: &'a FREContext, func_data: FREData, argc: u32, argv: *const FREObject, f: F, ) -> FREObject
where F: FnOnce(&CurrentContext<'a>, Option<&mut dyn Any>, &[Object<'a>]) -> R, R: Into<Object<'a>> + 'a,

A wrapper around FREFunction that provides a safe stack-level execution environment for the given closure.

In typical usage of this crate, this function should not be called directly.

§Safety

While all operations performed within this function are safe at the stack level, calling this function itself is unsafe and requires the following conditions:

  • func_data must either be constructed via Data::into_raw before ContextInitializer returns, or be a null pointer.
  • This function assumes it is invoked directly with arguments provided by the Flash runtime, meaning all arguments must be valid and consistent.

Violating these assumptions may lead to undefined behavior.

Trait Implementations§

Source§

impl Context for CurrentContext<'_>

Source§

fn as_handle(&self) -> NonNull<c_void>

Source§

fn is_valid(&self) -> bool

Returns whether the context is valid. Read more
Source§

fn as_ptr(&self) -> FREContext

Source§

fn event_dispatcher(&self) -> EventDispatcher

Returns an EventDispatcher used to perform asynchronous callbacks via the ActionScript event system.
Source§

fn trace(&self, message: impl ToUcstrLossy)

Sends a message to the debugger output. Read more
Source§

fn get_render_mode( &self, stage: Option<Object<'_>>, ) -> Result<RenderMode, FfiError>

Return Err if stage is non-null but not a Stage object Read more
Source§

fn set_render_source( &self, media_buffer: Object<'_>, sprite: Object<'_>, ) -> Result<(), FfiError>

air.media.MediaBuffer (AIR SDK 51) Read more
Source§

fn with_media_buffer<F, R>( &self, media_buffer: Object<'_>, f: F, ) -> Result<R, FfiError>
where F: FnOnce(MediaBufferDataAdapter<'_>) -> R,

This is a minimal safety wrapper around the underlying FFI. Its current placement, shape, and usage are not ideal, and it is expected to be refactored if the ANE C API allows more precise determination of an object’s concrete type.
Source§

impl<'a> Debug for CurrentContext<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for CurrentContext<'a>

§

impl<'a> RefUnwindSafe for CurrentContext<'a>

§

impl<'a> !Send for CurrentContext<'a>

§

impl<'a> !Sync for CurrentContext<'a>

§

impl<'a> Unpin for CurrentContext<'a>

§

impl<'a> UnsafeUnpin for CurrentContext<'a>

§

impl<'a> UnwindSafe for CurrentContext<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.