mirror of
https://github.com/fluencelabs/wasmer
synced 2024-12-15 15:15:40 +00:00
28 lines
667 B
Rust
28 lines
667 B
Rust
use std::mem;
|
|
use wasmer_runtime_core::{types::WasmExternType, vm::Ctx};
|
|
|
|
#[repr(transparent)]
|
|
#[derive(Copy, Clone)]
|
|
pub struct VarArgs {
|
|
pub pointer: u32, // assuming 32bit wasm
|
|
}
|
|
|
|
impl VarArgs {
|
|
pub fn get<T: Sized>(&mut self, ctx: &mut Ctx) -> T {
|
|
let ptr = emscripten_memory_pointer!(ctx.memory(0), self.pointer);
|
|
self.pointer += mem::size_of::<T>() as u32;
|
|
unsafe { (ptr as *const T).read() }
|
|
}
|
|
}
|
|
|
|
unsafe impl WasmExternType for VarArgs {
|
|
type Native = i32;
|
|
|
|
fn to_native(self) -> Self::Native {
|
|
self.pointer as _
|
|
}
|
|
fn from_native(n: Self::Native) -> Self {
|
|
Self { pointer: n as u32 }
|
|
}
|
|
}
|