let sum_typed: TypedFunction<(i32, i32), i32> = sum.typed(&mut store)?;
println!("Calling `sum` function (natively)...");
// Let's call the `sum` exported function. The parameters are
// statically typed Rust values of type `i32` and `i32`. The
// result, in this case particular case, in a unit of type `i32`.
let result = sum_typed.call(&mut store, 3, 4)?;
instance.exports.get_memory("memory")
Will give you the guest memory export.
WASM uses linear memory, so this memory export can growa9157e8
CI: Move ASan/UBSan to own build directory - Kaffeine
225b175
CMake: Set the minimum CMake version to 3.12 - Kaffeine
d0ecb5f
CMake: Rework the versioning - Kaffeine
f6172a2
CMake: Add version range validation - Kaffeine
0cea5b0
CMake: Remove the code for old CMake versions - Kaffeine
ee1b8ba
Merge pull request #7145 from infclass/for-ddnet4 - def-String
.
#[no_mangle]
pub fn add(left: u32, right: u32) -> u32 {
left + right
}
❯ cargo r -- target/wasm32-unknown-unknown/debug/guest.wasm
Finished dev [optimized + debuginfo] target(s) in 0.04s
Running `target/debug/host target/wasm32-unknown-unknown/debug/guest.wasm`
[host/src/main.rs:20] &result = [
I32(4),
]
#[no_mangle]
pub fn add(left: i32, right: i32) -> i32 {
unsafe { print_wasm(left) };
unsafe { print_wasm(right) };
left + right
}
extern {
fn print_wasm(a: i32);
}
fn print_wasm(_env: FunctionEnvMut<MyEnv>, a: i32) {
println!("{a}");
}
#[no_mangle]
pub fn add(left: i32, right: i32) -> i32 {
unsafe { print_wasm(left) };
unsafe { print_wasm(right) };
left + right
}
extern {
fn print_wasm(a: i32);
}
pub fn host_import(mut env: FunctionEnvMut<()>, memory: Memory, ptr: WasmPtr<u32>) {
let memory = memory.view(&env);
let derefed_ptr = ptr.deref(&memory);
let inner_val: u32 = derefed_ptr.read().expect("pointer in bounds");
println!("Got {} from Wasm memory address 0x{:X}", inner_val, ptr.offset());
// update the value being pointed to
derefed_ptr.write(inner_val + 1).expect("pointer in bounds");
}
@Jupstar ✪ the docs for WasmPtr show thisfn accept_str(mut env: FunctionEnvMut<()>, memory: Memory, ptr: WasmPtr<u8>, len: u32) {
❯ cargo r -- target/wasm32-unknown-unknown/debug/guest.wasm
Finished dev [optimized + debuginfo] target(s) in 0.04s
Running `target/debug/host target/wasm32-unknown-unknown/debug/guest.wasm`
2
2
adding 2 to 2
[host/src/main.rs:39] &result = [
I32(4),
]
#[no_mangle]
pub fn add(left: i32, right: i32) -> i32 {
unsafe {
print_wasm(left);
print_wasm(right);
let str = format!("adding {} to {}", left, right);
accept_str(str.as_ptr(), str.len() as u32);
}
left + right
}
extern {
fn print_wasm(a: i32);
fn accept_str(ptr: *const u8, len: u32);
}
let instance = Instance::new(&mut store, &module, &import_object)?;
let env = env.as_mut(&mut store);
let mem = instance.exports.get_memory("memory")?;
env.memory = Some(mem.clone());
path = "…"
chat all hi
!screenshot_2023-09-08_17-24-14CLIENT_VERSIONNR
is used to declare DDNet protocol capabilities. It makes no sense for a forked client to suddenly report different DDNet client version for the same codebase. Equally for the server code it makes no sense to report SERVER_DEMO_CLIENT
DDNet version different (lower) than what is supported by this code base (and e.g. record network events generated for some old client version).
This way the mods can define their project with own version after DDNet project()
to at the ...