Skip to content

Commit

Permalink
Handle object returns from get_raw_buffer_to_array (#468)
Browse files Browse the repository at this point in the history
  • Loading branch information
shanemadden authored Nov 28, 2023
1 parent c96cff2 commit 5a80f57
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
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(()),
}
}
}

0 comments on commit 5a80f57

Please sign in to comment.