Page 1 of 1

NSData support in LCValueArrayValueFromObjcValue

Posted: Wed May 07, 2014 7:10 am
by monte
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

Re: NSData support in LCValueArrayValueFromObjcValue

Posted: Thu May 08, 2014 9:13 am
by LCMark
@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 ].

Re: NSData support in LCValueArrayValueFromObjcValue

Posted: Fri May 09, 2014 12:04 am
by monte
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....

Re: NSData support in LCValueArrayValueFromObjcValue

Posted: Fri May 09, 2014 9:18 am
by Thierry
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!