Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle object returns from get_raw_buffer_to_array #468

Merged
merged 3 commits into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Unreleased

- Implement `JsCollectionIntoValue` for `Direction`, making the `JsHashMap` returned by
`game::map::describe_exits` able to be used
- Handle object return properly from `RoomTerrain::get_raw_buffer_to_array` when built in dev mode

0.16.1 (2023-10-11)
===================
Expand Down
11 changes: 9 additions & 2 deletions src/objects/impls/room_terrain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ extern "C" {

// and when called with a destination, it can only ever return a return code int
#[wasm_bindgen(method, js_name = getRawBuffer)]
fn get_raw_buffer_to_array_internal(this: &RoomTerrain, destination: &Uint8Array) -> i8;
fn get_raw_buffer_to_array_internal(this: &RoomTerrain, destination: &Uint8Array) -> JsValue;
}

impl RoomTerrain {
Expand Down Expand Up @@ -58,6 +58,13 @@ impl RoomTerrain {
/// [Screeps documentation](https://docs.screeps.com/api/#Room.Terrain.getRawBuffer)
#[inline]
pub fn get_raw_buffer_to_array(&self, destination: &Uint8Array) -> Result<(), ErrorCode> {
ErrorCode::result_from_i8(self.get_raw_buffer_to_array_internal(destination))
let val = self.get_raw_buffer_to_array_internal(destination);

// val is integer if error; if object it's another reference to the Uint8Array;
// function was successful in that case
match val.as_f64() {
Some(n) => ErrorCode::result_from_i8(n as i8),
None => Ok(()),
}
}
}
Loading