type per command, binding generation macros, nix package #4
					 6 changed files with 53 additions and 63 deletions
				
			
		| 
						 | 
					@ -1405,6 +1405,14 @@ struct CharGridCommand */*notnull*/ sp_chargridcommand_clone(struct CharGridComm
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
void sp_chargridcommand_free(struct CharGridCommand */*notnull*/ instance);
 | 
					void sp_chargridcommand_free(struct CharGridCommand */*notnull*/ instance);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * Moves the provided [CharGrid] into a new [CharGridCommand],
 | 
				
			||||||
 | 
					 * leaving other fields as their default values.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * This function is part of the `chargridcommand` module.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					struct CharGridCommand */*notnull*/ sp_chargridcommand_from_grid(CharGrid */*notnull*/ grid);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * Gets a reference to the field `grid` of the [`servicepoint::CharGridCommand`].
 | 
					 * Gets a reference to the field `grid` of the [`servicepoint::CharGridCommand`].
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
| 
						 | 
					@ -1424,6 +1432,19 @@ void sp_chargridcommand_get_origin(struct CharGridCommand */*notnull*/ command,
 | 
				
			||||||
                                   size_t */*notnull*/ origin_x,
 | 
					                                   size_t */*notnull*/ origin_x,
 | 
				
			||||||
                                   size_t */*notnull*/ origin_y);
 | 
					                                   size_t */*notnull*/ origin_y);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * Show UTF-8 encoded text on the screen.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * The passed [CharGrid] gets consumed.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * Returns: a new [CharGridCommand] instance.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * This function is part of the `chargridcommand` module.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					struct CharGridCommand */*notnull*/ sp_chargridcommand_new(CharGrid */*notnull*/ grid,
 | 
				
			||||||
 | 
					                                                           size_t origin_x,
 | 
				
			||||||
 | 
					                                                           size_t origin_y);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * Sets the value of field `grid` of the [`servicepoint::CharGridCommand`].
 | 
					 * Sets the value of field `grid` of the [`servicepoint::CharGridCommand`].
 | 
				
			||||||
 * The provided value is moved into the instance, potentially invalidating previously taken references.
 | 
					 * The provided value is moved into the instance, potentially invalidating previously taken references.
 | 
				
			||||||
| 
						 | 
					@ -1489,48 +1510,6 @@ struct ClearCommand */*notnull*/ sp_clearcommand_new(void);
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
struct Packet *sp_clearcommand_try_into_packet(struct ClearCommand */*notnull*/ instance);
 | 
					struct Packet *sp_clearcommand_try_into_packet(struct ClearCommand */*notnull*/ instance);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					 | 
				
			||||||
 * Moves the provided [CharGrid] into a new [CharGridCommand],
 | 
					 | 
				
			||||||
 * leaving other fields as their default values.
 | 
					 | 
				
			||||||
 *
 | 
					 | 
				
			||||||
 * This function is part of the `cmd_chargrid` module.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
struct CharGridCommand */*notnull*/ sp_cmd_chargrid_from_grid(CharGrid */*notnull*/ grid);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/**
 | 
					 | 
				
			||||||
 * Show UTF-8 encoded text on the screen.
 | 
					 | 
				
			||||||
 *
 | 
					 | 
				
			||||||
 * The passed [CharGrid] gets consumed.
 | 
					 | 
				
			||||||
 *
 | 
					 | 
				
			||||||
 * Returns: a new [CharGridCommand] instance.
 | 
					 | 
				
			||||||
 *
 | 
					 | 
				
			||||||
 * This function is part of the `cmd_chargrid` module.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
struct CharGridCommand */*notnull*/ sp_cmd_chargrid_new(CharGrid */*notnull*/ grid,
 | 
					 | 
				
			||||||
                                                        size_t origin_x,
 | 
					 | 
				
			||||||
                                                        size_t origin_y);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/**
 | 
					 | 
				
			||||||
 * Moves the provided [Cp437Grid] into a new [Cp437GridCommand],
 | 
					 | 
				
			||||||
 * leaving other fields as their default values.
 | 
					 | 
				
			||||||
 *
 | 
					 | 
				
			||||||
 * This function is part of the `cmd_cp437grid` module.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
struct Cp437GridCommand */*notnull*/ sp_cmd_cp437grid_from_grid(Cp437Grid */*notnull*/ grid);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/**
 | 
					 | 
				
			||||||
 * Show text on the screen.
 | 
					 | 
				
			||||||
 *
 | 
					 | 
				
			||||||
 * The text is sent in the form of a 2D grid of [CP-437] encoded characters.
 | 
					 | 
				
			||||||
 *
 | 
					 | 
				
			||||||
 * The origin is relative to the top-left of the display.
 | 
					 | 
				
			||||||
 *
 | 
					 | 
				
			||||||
 * This function is part of the `cmd_cp437grid` module.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
struct Cp437GridCommand */*notnull*/ sp_cmd_cp437grid_new(Cp437Grid */*notnull*/ grid,
 | 
					 | 
				
			||||||
                                                          size_t origin_x,
 | 
					 | 
				
			||||||
                                                          size_t origin_y);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 *Clones a [`Cp437Grid`] instance.
 | 
					 *Clones a [`Cp437Grid`] instance.
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
| 
						 | 
					@ -1672,6 +1651,14 @@ struct Cp437GridCommand */*notnull*/ sp_cp437gridcommand_clone(struct Cp437GridC
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
void sp_cp437gridcommand_free(struct Cp437GridCommand */*notnull*/ instance);
 | 
					void sp_cp437gridcommand_free(struct Cp437GridCommand */*notnull*/ instance);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * Moves the provided [Cp437Grid] into a new [Cp437GridCommand],
 | 
				
			||||||
 | 
					 * leaving other fields as their default values.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * This function is part of the `cp437gridcommand` module.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					struct Cp437GridCommand */*notnull*/ sp_cp437gridcommand_from_grid(Cp437Grid */*notnull*/ grid);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * Gets a reference to the field `grid` of the [`servicepoint::Cp437GridCommand`].
 | 
					 * Gets a reference to the field `grid` of the [`servicepoint::Cp437GridCommand`].
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
| 
						 | 
					@ -1691,6 +1678,19 @@ void sp_cp437gridcommand_get_origin(struct Cp437GridCommand */*notnull*/ command
 | 
				
			||||||
                                    size_t */*notnull*/ origin_x,
 | 
					                                    size_t */*notnull*/ origin_x,
 | 
				
			||||||
                                    size_t */*notnull*/ origin_y);
 | 
					                                    size_t */*notnull*/ origin_y);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * Show text on the screen.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * The text is sent in the form of a 2D grid of [CP-437] encoded characters.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * The origin is relative to the top-left of the display.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * This function is part of the `cp437gridcommand` module.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					struct Cp437GridCommand */*notnull*/ sp_cp437gridcommand_new(Cp437Grid */*notnull*/ grid,
 | 
				
			||||||
 | 
					                                                             size_t origin_x,
 | 
				
			||||||
 | 
					                                                             size_t origin_y);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * Sets the value of field `grid` of the [`servicepoint::Cp437GridCommand`].
 | 
					 * Sets the value of field `grid` of the [`servicepoint::Cp437GridCommand`].
 | 
				
			||||||
 * The provided value is moved into the instance, potentially invalidating previously taken references.
 | 
					 * The provided value is moved into the instance, potentially invalidating previously taken references.
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -14,7 +14,7 @@ wrap_fields!(CharGridCommand;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
wrap_origin_accessors!(CharGridCommand);
 | 
					wrap_origin_accessors!(CharGridCommand);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
wrap_functions!(cmd_chargrid;
 | 
					wrap_functions!(associate CharGridCommand;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /// Show UTF-8 encoded text on the screen.
 | 
					    /// Show UTF-8 encoded text on the screen.
 | 
				
			||||||
    ///
 | 
					    ///
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -14,7 +14,7 @@ wrap_fields!(Cp437GridCommand;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
wrap_origin_accessors!(Cp437GridCommand);
 | 
					wrap_origin_accessors!(Cp437GridCommand);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
wrap_functions!(cmd_cp437grid;
 | 
					wrap_functions!(associate Cp437GridCommand;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /// Show text on the screen.
 | 
					    /// Show text on the screen.
 | 
				
			||||||
    ///
 | 
					    ///
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,5 +1,5 @@
 | 
				
			||||||
use crate::{
 | 
					use crate::{
 | 
				
			||||||
    macros::{derive_clone, derive_free, wrap_functions},
 | 
					    macros::{derive_clone, derive_free, wrap_functions, wrap_methods},
 | 
				
			||||||
    mem::{
 | 
					    mem::{
 | 
				
			||||||
        heap_clone, heap_drop, heap_move, heap_move_nonnull, heap_move_ok,
 | 
					        heap_clone, heap_drop, heap_move, heap_move_nonnull, heap_move_ok,
 | 
				
			||||||
        heap_remove,
 | 
					        heap_remove,
 | 
				
			||||||
| 
						 | 
					@ -11,7 +11,6 @@ use servicepoint::{
 | 
				
			||||||
    HardResetCommand, Packet, TypedCommand,
 | 
					    HardResetCommand, Packet, TypedCommand,
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
use std::ptr::{null_mut, NonNull};
 | 
					use std::ptr::{null_mut, NonNull};
 | 
				
			||||||
use crate::macros::wrap_methods;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
/// Pointer to one of the available command structs.
 | 
					/// Pointer to one of the available command structs.
 | 
				
			||||||
#[repr(C)]
 | 
					#[repr(C)]
 | 
				
			||||||
| 
						 | 
					@ -168,11 +167,12 @@ impl Drop for GenericCommand {
 | 
				
			||||||
                CommandTag::BitmapLegacy => heap_drop(self.data.bitmap_legacy),
 | 
					                CommandTag::BitmapLegacy => heap_drop(self.data.bitmap_legacy),
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        *self = Self::INVALID;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
wrap_functions!(associate GenericCommand;
 | 
					wrap_functions!(associate GenericCommand;
 | 
				
			||||||
 | 
					 | 
				
			||||||
    /// Tries to turn a [Packet] into a [GenericCommand].
 | 
					    /// Tries to turn a [Packet] into a [GenericCommand].
 | 
				
			||||||
    ///
 | 
					    ///
 | 
				
			||||||
    /// The packet is dropped in the process.
 | 
					    /// The packet is dropped in the process.
 | 
				
			||||||
| 
						 | 
					@ -181,7 +181,7 @@ wrap_functions!(associate GenericCommand;
 | 
				
			||||||
    fn try_from_packet(
 | 
					    fn try_from_packet(
 | 
				
			||||||
        packet: NonNull<Packet>,
 | 
					        packet: NonNull<Packet>,
 | 
				
			||||||
    ) -> NonNull<GenericCommand> {
 | 
					    ) -> NonNull<GenericCommand> {
 | 
				
			||||||
        let packet = *unsafe { Box::from_raw(packet.as_ptr()) };
 | 
					        let packet = unsafe { heap_remove(packet) };
 | 
				
			||||||
        let result = servicepoint::TypedCommand::try_from(packet)
 | 
					        let result = servicepoint::TypedCommand::try_from(packet)
 | 
				
			||||||
            .map(|value| match value {
 | 
					            .map(|value| match value {
 | 
				
			||||||
                TypedCommand::Clear(clear) => GenericCommand {
 | 
					                TypedCommand::Clear(clear) => GenericCommand {
 | 
				
			||||||
| 
						 | 
					@ -252,7 +252,6 @@ wrap_functions!(associate GenericCommand;
 | 
				
			||||||
            });
 | 
					            });
 | 
				
			||||||
        heap_move_nonnull(result)
 | 
					        heap_move_nonnull(result)
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					 | 
				
			||||||
);
 | 
					);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
wrap_methods! { GenericCommand;
 | 
					wrap_methods! { GenericCommand;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -11,7 +11,7 @@ use std::ptr::NonNull;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
wrap_grid!(Bitmap, bool);
 | 
					wrap_grid!(Bitmap, bool);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
wrap_functions!(bitmap;
 | 
					wrap_functions!(associate Bitmap;
 | 
				
			||||||
    /// Creates a new [Bitmap] with the specified dimensions.
 | 
					    /// Creates a new [Bitmap] with the specified dimensions.
 | 
				
			||||||
    ///
 | 
					    ///
 | 
				
			||||||
    /// # Arguments
 | 
					    /// # Arguments
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -10,28 +10,19 @@ use std::ptr::NonNull;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
wrap_grid!(Cp437Grid, u8);
 | 
					wrap_grid!(Cp437Grid, u8);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
wrap_functions!(cp437grid;
 | 
					wrap_functions!(associate Cp437Grid;
 | 
				
			||||||
 | 
					 | 
				
			||||||
    /// Creates a new [Cp437Grid] with the specified dimensions.
 | 
					    /// Creates a new [Cp437Grid] with the specified dimensions.
 | 
				
			||||||
    ///
 | 
					    ///
 | 
				
			||||||
    /// returns: [Cp437Grid] initialized to 0.
 | 
					    /// returns: [Cp437Grid] initialized to 0.
 | 
				
			||||||
    fn new(
 | 
					    fn new(width: usize, height: usize) -> NonNull<Cp437Grid> {
 | 
				
			||||||
        width: usize,
 | 
					 | 
				
			||||||
        height: usize,
 | 
					 | 
				
			||||||
    ) -> NonNull<Cp437Grid> {
 | 
					 | 
				
			||||||
        heap_move_nonnull(Cp437Grid::new(width, height))
 | 
					        heap_move_nonnull(Cp437Grid::new(width, height))
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /// Loads a [Cp437Grid] with the specified dimensions from the provided data.
 | 
					    /// Loads a [Cp437Grid] with the specified dimensions from the provided data.
 | 
				
			||||||
    fn load(
 | 
					    fn load(width: usize, height: usize, data: ByteSlice) -> *mut Cp437Grid {
 | 
				
			||||||
        width: usize,
 | 
					 | 
				
			||||||
        height: usize,
 | 
					 | 
				
			||||||
        data: ByteSlice,
 | 
					 | 
				
			||||||
    ) -> *mut Cp437Grid {
 | 
					 | 
				
			||||||
        let data = unsafe { data.as_slice() };
 | 
					        let data = unsafe { data.as_slice() };
 | 
				
			||||||
        heap_move_some(Cp437Grid::load(width, height, data))
 | 
					        heap_move_some(Cp437Grid::load(width, height, data))
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					 | 
				
			||||||
);
 | 
					);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
wrap_methods!(Cp437Grid;
 | 
					wrap_methods!(Cp437Grid;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue