From ba97dc5f57da049f9cada870000bffe556dec38a Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Thu, 23 Aug 2018 10:22:14 +0200 Subject: cocoa_bridge: Continue outline of Objective C callable Add some more structure to the function that will be called from Objective C code. * Give it a name, `parse_mappings` (not very thoroughly considered) * Initialise some Foundation data structures to mirror our Rust ones * Add the beginning of a struct that will be the ObjC version of our `MapGroup` struct, containing `NSDictionary`ies. * Move the `extern crate` into `lib.rs`, I keep forgetting that's where they go. * Add a test that just calls `parse_mappings` to check that the code compiles. parser::MapGroup: Make both its fields public to enable us to access them from `cocoa_bridge`. Used this helpful example as a reference for the Rust Cocoa code: https://github.com/servo/core-foundation-rs/blob/c99c05c/cocoa/examples/hello_world.rs --- src/cocoa_bridge.rs | 32 +++++++++++++++++++++++++++++--- src/lib.rs | 2 ++ src/parser.rs | 4 ++-- 3 files changed, 33 insertions(+), 5 deletions(-) diff --git a/src/cocoa_bridge.rs b/src/cocoa_bridge.rs index 58d74d2..ea88661 100644 --- a/src/cocoa_bridge.rs +++ b/src/cocoa_bridge.rs @@ -1,13 +1,39 @@ -extern crate cocoa; +use cocoa::base::nil; +use cocoa::foundation::{NSArray, NSAutoreleasePool, NSDictionary}; use MapGroup; -pub extern "C" fn x() { +#[repr(C)] +struct renameMeMapGroup { +} + +pub extern "C" fn parse_mappings() { let sample_maps = "map k map j"; - let map_group = MapGroup::parse(sample_maps); + let map_group = MapGroup::parse(sample_maps).unwrap(); unsafe { + let _pool = NSAutoreleasePool::new(nil); + + let maps = NSDictionary::init(nil).autorelease(); + let modes = NSDictionary::init(nil).autorelease(); + + for (trigger, action) in map_group.maps { + let t = NSArray::array(nil).autorelease(); + } + + for (trigger, modes) in map_group.modes { + } + } +} + + +mod tests { + use super::*; + + #[test] + fn parse_mappings_makes_cocoa_mappings() { + parse_mappings(); } } diff --git a/src/lib.rs b/src/lib.rs index c2d2f9f..e6260ed 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,3 +1,5 @@ +extern crate cocoa; + #[macro_use] extern crate combine; diff --git a/src/parser.rs b/src/parser.rs index a34edff..d5cd860 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -51,8 +51,8 @@ struct Mode { #[derive(Debug, PartialEq)] pub struct MapGroup { - maps: MapCollection, - modes: HashMap, + pub maps: MapCollection, + pub modes: HashMap, } #[derive(Debug, PartialEq)] -- cgit v1.2.3