Skip to content

Commit

Permalink
convert cp437-grid to tuple
Browse files Browse the repository at this point in the history
  • Loading branch information
kaesaecracker committed Sep 7, 2024
1 parent 9ab87f6 commit eb43ccf
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 19 deletions.
2 changes: 1 addition & 1 deletion crates/servicepoint_binding_c/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ pub unsafe extern "C" fn sp_command_cp437_data(
let grid = *Box::from_raw(grid);
Box::into_raw(Box::new(SPCommand(servicepoint::Command::Cp437Data(
Origin::new(x, y),
grid.actual,
grid.0,
))))
}

Expand Down
28 changes: 10 additions & 18 deletions crates/servicepoint_binding_c/src/cp437_grid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,11 @@ use servicepoint::{DataRef, Grid};
/// sp_cp437_grid_set(grid, 0, 0, '!');
/// sp_cp437_grid_free(grid);
/// ```
pub struct SPCp437Grid {
pub(crate) actual: servicepoint::Cp437Grid,
}
pub struct SPCp437Grid(pub(crate) servicepoint::Cp437Grid);

impl Clone for SPCp437Grid {
fn clone(&self) -> Self {
SPCp437Grid {
actual: self.actual.clone(),
}
SPCp437Grid(self.0.clone())
}
}

Expand All @@ -44,9 +40,7 @@ pub unsafe extern "C" fn sp_cp437_grid_new(
width: usize,
height: usize,
) -> *mut SPCp437Grid {
Box::into_raw(Box::new(SPCp437Grid {
actual: servicepoint::Cp437Grid::new(width, height),
}))
Box::into_raw(Box::new(SPCp437Grid(servicepoint::Cp437Grid::new(width, height))))
}

/// Loads a `SPCp437Grid` with the specified dimensions from the provided data.
Expand All @@ -73,9 +67,7 @@ pub unsafe extern "C" fn sp_cp437_grid_load(
data_length: usize,
) -> *mut SPCp437Grid {
let data = std::slice::from_raw_parts(data, data_length);
Box::into_raw(Box::new(SPCp437Grid {
actual: servicepoint::Cp437Grid::load(width, height, data),
}))
Box::into_raw(Box::new(SPCp437Grid(servicepoint::Cp437Grid::load(width, height, data))))
}

/// Clones a `SPCp437Grid`.
Expand Down Expand Up @@ -134,7 +126,7 @@ pub unsafe extern "C" fn sp_cp437_grid_get(
x: usize,
y: usize,
) -> u8 {
(*cp437_grid).actual.get(x, y)
(*cp437_grid).0.get(x, y)
}

/// Sets the value of the specified position in the `SPCp437Grid`.
Expand Down Expand Up @@ -164,7 +156,7 @@ pub unsafe extern "C" fn sp_cp437_grid_set(
y: usize,
value: u8,
) {
(*cp437_grid).actual.set(x, y, value);
(*cp437_grid).0.set(x, y, value);
}

/// Sets the value of all cells in the `SPCp437Grid`.
Expand All @@ -185,7 +177,7 @@ pub unsafe extern "C" fn sp_cp437_grid_fill(
cp437_grid: *mut SPCp437Grid,
value: u8,
) {
(*cp437_grid).actual.fill(value);
(*cp437_grid).0.fill(value);
}

/// Gets the width of the `SPCp437Grid` instance.
Expand All @@ -203,7 +195,7 @@ pub unsafe extern "C" fn sp_cp437_grid_fill(
pub unsafe extern "C" fn sp_cp437_grid_width(
cp437_grid: *const SPCp437Grid,
) -> usize {
(*cp437_grid).actual.width()
(*cp437_grid).0.width()
}

/// Gets the height of the `SPCp437Grid` instance.
Expand All @@ -221,7 +213,7 @@ pub unsafe extern "C" fn sp_cp437_grid_width(
pub unsafe extern "C" fn sp_cp437_grid_height(
cp437_grid: *const SPCp437Grid,
) -> usize {
(*cp437_grid).actual.height()
(*cp437_grid).0.height()
}

/// Gets an unsafe reference to the data of the `SPCp437Grid` instance.
Expand All @@ -239,7 +231,7 @@ pub unsafe extern "C" fn sp_cp437_grid_height(
pub unsafe extern "C" fn sp_cp437_grid_unsafe_data_ref(
cp437_grid: *mut SPCp437Grid,
) -> SPByteSlice {
let data = (*cp437_grid).actual.data_ref_mut();
let data = (*cp437_grid).0.data_ref_mut();
SPByteSlice {
start: data.as_mut_ptr_range().start,
length: data.len(),
Expand Down

0 comments on commit eb43ccf

Please sign in to comment.