NSData support in LCValueArrayValueFromObjcValue

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, LCMark

Locked
monte
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1564
Joined: Fri Jan 13, 2012 1:47 am
Contact:

NSData support in LCValueArrayValueFromObjcValue

Post by monte » Wed May 07, 2014 7:10 am

Hi

Is there any reason why LCValueArrayValueFromObjcValue doesn't support NSData? I'm looking for a simple way to return a multi-dimensional array with some values that are unicode and seeing as NSString support is all Mac Roman encoding I thought NSData would work but it's not being tested for... from the looks of things I just need to add:

Code: Select all

if ([src isKindOfClass: [NSData class]])
		return LCValueStore(var, kLCValueOptionAsObjcData, &src);
PS Will NSString support be upgraded to unicode in LC 7? ... please say yes.

Cheers

Monte
LiveCode User Group on Facebook : http://FaceBook.com/groups/LiveCodeUsers/

LCMark
Livecode Staff Member
Livecode Staff Member
Posts: 1211
Joined: Thu Apr 11, 2013 11:27 am

Re: NSData support in LCValueArrayValueFromObjcValue

Post by LCMark » Thu May 08, 2014 9:13 am

@monte: The reason I did it that was to make arrays going in and out symmetric... There's no way for an array coming from LiveCode going to an external to know whether it should encode its elements as data or string (there's no distinction in the current pre-7.0 engine) -- however, on reflection, this probably being a little too conservative so making it so that NSData gets stored as binary data when going back into LiveCode does no harm.

In terms of LC7 - yes, the externals interface (when it arrives!) in LC7 will promote 'string' to 'unicode string'. If a variable (or element) holds a String unicode will pass through to NSString, and if a variable (or element) holds a binary string it will pass through to NSData. Note that because in LC7, binary strings and text strings are distinguished in the engine then the array conversion can be symmetric. [ We can put in the external glue code the compatibility conversion of natively encoded strings being treated as either a text string or binary data - it will depend on how you request the contents ].

monte
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1564
Joined: Fri Jan 13, 2012 1:47 am
Contact:

Re: NSData support in LCValueArrayValueFromObjcValue

Post by monte » Fri May 09, 2014 12:04 am

OK, thanks, I've added it to the pull request against your fork along with a few more tweaks. Good to hear about the unicode stuff as it should make a few people happy that they can pass unicode strings to my externals and me happy that I don't need to require an extra encoding parameter. Currently having an issue with array keys. I'm guessing I'm the first one to actually try to return an array or dictionary....
LiveCode User Group on Facebook : http://FaceBook.com/groups/LiveCodeUsers/

Thierry
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 875
Joined: Wed Nov 22, 2006 3:42 pm

Re: NSData support in LCValueArrayValueFromObjcValue

Post by Thierry » Fri May 09, 2014 9:18 am

monte wrote:I'm guessing I'm the first one to actually try to return an array or dictionary....
Hi Monte,

For the record, no, you're not!
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!

Locked

Return to “Engine Contributors”