Menu

not again :(

Help
matt
2002-06-24
2002-06-24
  • matt

    matt - 2002-06-24

    well, i guess it's not surprising that this doesn't work. however, i found some weird behavior that i thought you should know about...

    Moxic.pm

    sub applicationWillFinishLaunching {
        my ($self, $notification) = @_;

        my $prefs = NSUserDefaults->standardUserDefaults;
        my $defaults = NSMutableDictionary->dictionary;

        my $connectionDefaults = [{
            Connections            =>    "Untitled",
            PreferencesNickField        =>    "",
            PreferencesUsernameField    =>    "",
            PreferencesRealNameField    =>    "",
            PreferencesServerField        =>    "",
            PreferencesPortField        =>    "6667"
        }];
        NSLog($connectionDefaults);
        $defaults->setObject_forKey($connectionDefaults, "connectionDefaults");
        NSLog($defaults->objectForKey("connectionDefaults"));
        $prefs->registerDefaults($defaults);
        NSLog($prefs->objectForKey("connectionDefaults"));

        # Create the new controller object
        $self->{'wc'} = MoxicWindowController->new;

        return 1;
    }

    Here's what the NSLog()s produce:

    2002-06-24 07:18:37.229 Moxic[1046] ARRAY(0x2c5b94)
    2002-06-24 07:18:37.254 Moxic[1046] NSObject=HASH(0x2c5c84)
    2002-06-24 07:18:37.272 Moxic[1046] NSObject=HASH(0x2cbef0)

    there are two things of concern here. the first is, obviously, that after fetching the array from $defaults or $prefs, perl says it's a hash, not an array. the second odd behavior is that they're both objects of class NSObject. i'm assuming that has something to do with the way cb converts perl objects to obj-c objects though.

    anyways, since perl says the object stored in $prefs or $default is a hash, not array, this method fails...

    MoxicDataSource.pm

    sub setDefaults {
        my ($self, $defaults) = @_;
        @{$self->{'data'}} = @{$defaults};
    }

    2002-06-24 07:18:37.822 Moxic[1046] Perl error: Not an ARRAY reference at /Users/matt/Documents/Projects/Moxic/build/Moxic.app/Contents/Resources/MoxicDataSource.pm line 50.

    is there a way i can force perl to either ignore that or some other way to treat $defaults as an array (which is should be)?

    thanks again,
    matt

    ps: for now, i've been storing the $connectionDefaults in $self :\

     
    • matt

      matt - 2002-06-24

      NSLog(Data::Dumper->Dump([$prefs->objectForKey("connectionDefaults")], ["*conDef"]));

      2002-06-24 09:06:18.099 Moxic[1559] %conDef = bless( (
                         'NATIVE_OBJ' => 3183264
                       ), 'NSObject' );

      note: i changed connectionDefaults from an array containing a hash to just a hash, so %conDef is right (as opposed to @conDef)

       
    • Sherm Pendley

      Sherm Pendley - 2002-06-24

      Nothing weird here, just not as much magic as you were hoping for. :-(

      The only automatic type conversion that's complete right now is String <-> NSString. When you pass a Perl array to an ObjC method that expects an object, a CBPerlArray object is created to "wrap" the Perl array, but that class is basically just a skeleton right now - the method implementations for it are no-ops. The same is true for hashes.

       

Log in to post a comment.