luapower / objc

Objective-C & Cocoa Bridge
http://luapower.com/objc
25 stars 7 forks source link

Fix OSX 10.10 change that made properties where before were just getter methods #4

Closed capr closed 6 years ago

capr commented 6 years ago

OSX 10.10+ modernized Cocoa by making properties out of what before were getter methods with the same name. This does not break compatibility in Obj-C because getter invocation is still available for writing backwards-compatible code, but it is a problem in Lua which can't distinguish between method invocation and table access at runtime. So if we care about writing code that works on OSX older than 10.10 we have to either a) renounce dot notation for reading properties (we can still set properties with dot notation although that would be inconsistent), b) have every non-void zero-arg method work only with dot notation, whether it was declared as a property or not, or c) leave things mostly as they are and dump it on the user (which only increases their PTSD and other chronic conditions they might have from exposure to OOP, ObjC an Cocoa). Since all options suck, we should probably make a config option and let the user choose their poison.

capr commented 6 years ago

Solution: new API was introduced to deal with this:

objc.use_properties(true|false) -> old_value_of_use_properties objc.with_properties(func) objc.without_properties(func)

This API controls accessing properties via dot notation. Dot notation is disabled by default and can be enabled only for the sections of code that need it. This means old user code using getters doesn't need to be updated, but old code using dot notation does.