Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Old scripts not working - some shims disappeared? #10

Open
samdeane opened this issue Mar 26, 2014 · 9 comments
Open

Old scripts not working - some shims disappeared? #10

samdeane opened this issue Mar 26, 2014 · 9 comments

Comments

@samdeane
Copy link
Contributor

I recently upgraded from JSTalk to CocoaScript, and it seems like a bunch of old scripts aren’t working any more.

In particular, log() used to work and now doesn’t, and somensarray.length() used to work whereas now somensarray.count() is required.

I get the impression that what may be happening is that the point at which some bridging takes place has shifted somehow, so that things which were previously treated as (converted to?) javascript objects are now being treated as native cocoa objects.

Or something :)

Does this ring any bells? Have I missed an option somewhere that I’m supposed to have configured?

@samdeane
Copy link
Contributor Author

Either that, or (as the title suggests), perhaps there was a mapping layer for certain functions somewhere that has gone away?

@ccgus
Copy link
Owner

ccgus commented Mar 26, 2014

CocoaScript uses a different bridge, so some things that JSCocoa (the previous bridge) did automatically aren't done anymore.

Try print() instead of log (or put print = log somewhere at the top of your script). I'll see about adding length() support - should be easy enough…

@samdeane
Copy link
Contributor Author

That would explain it - thought it might be something along those lines.

I did add a log -> print alias to the preamble we add to user scripts, and we can easily add length as a category on NSArray, but it started feeling like the set of changes was potentially larger (and perhaps a bit unknown…).

We want to do our best not to break all our users scripts when we switch. I guess you’re going to go through the same thing with 4.4 of Acorn.

If we can figure out some reasonable set of the things that will break (even if we can’t get it exhaustive, we can hopefully find the common ones that crop up repeatedly), then we can maybe add a compatibility layer of mappings which we can use whilst deprecating the broken stuff?

@ccgus
Copy link
Owner

ccgus commented Mar 27, 2014

Mapping should be possible. I never used log or print or length in my scripts - so I don't think it ever came up :)

@samdeane
Copy link
Contributor Author

samdeane commented May 1, 2014

The big one seems to be length. There's a hack in JSCocoaController which did some special case stuff for anything that supported the obejctAtIndex method - including switching any calls to "length" to use "count" instead.

I guess a category in the host app will fix it (if the host app wants to).

Confused us for a while because it was magically working for a custom array class of ours that had nothing to do with NSArray (because they were testing for objectAtIndex rather than just some relationship with NSArray).

@ccgus
Copy link
Owner

ccgus commented May 1, 2014

If you have any small snippets of code that used to work, that don't work - those would be great to have for testing (and fixing) in CocoaScript.

@ccgus
Copy link
Owner

ccgus commented May 1, 2014

Looking at the source for CocoaScript - looks like I added a special case for length at some point. And I'm about to push up a commit that adds support for log as well.

@samdeane
Copy link
Contributor Author

We're keeping a track of the issues we spot here:

https://github.com/sketchplugins/cocoascript-migration

@samdeane
Copy link
Contributor Author

Some of that stuff is Sketch specific, mind you...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants