ObjectiveC integration into Codea — revised demo

@jfperusse i’m glad to know it’s at least possible!

Of course it’s your business what you’re interested in doing and not doing, and really I’m still just thrilled to have any objective-C bridge at all, but as far as this goes, my two cents is that objc.my is a good deal more lightweight than viewer.isStandalone and and, especially if I’m referencing a lot of custom classes, having viewer.isStandalone and all over the place will get pretty severely cluttered.

I’m not married to objc.my specifically, mind you, I’d be happy with any prefix you thought appropriate, it would just be nice if it was, well, terse.

@UberGoober I understand your point :slight_smile: The main reason I’m not comfortable with the objc.my approach is that I wouldn’t expect a statement such as objc.my.someclass.somemethod to be nil when I look at it, I would expect it to give a nil reference error, when looking at it as a Lua programmer. But maybe there could be another way that would make it look like valid code?

In more modern languages, this would be a perfect use for null coalescing operators. local currentTurn = obj.TurnManager?.currentTurn ?? 1

Hmm, seems like you should be able to communicate that meaning with a prefix. Might I suggest any of these:

  • objc.nullable
  • objc.optional
  • objc.opt
  • objc.question
  • objc.q

…?

I suppose it could also be a function:

objc.custom(…custom reference here…)

…which always either returns the reference or null, as in:


local currentTurn = obj.custom(TurnManager.currentTurn)

@jfperusse can I add this to WebRepo? It’s very useful.

Of course you can! :+1: