The History & Design of LuaCocoa Eric Wing @ewingfighter http://playcontrol.net/opensource/LuaCocoa Background: Lots of different hats to wear • Worked on Globalstar (orbital satellite global communication system) • Cross-platform: Linux, Mac, Windows, iOS, Android, FreeBSD, Solaris, IRIX • Scientific Visualization (OpenGL) • Native Cocoa Application development (Mac, iOS) • Video Game Engines • Open Source: SDL, OpenSceneGraph, CMake, OpenAL • C, C++, Obj-C, Lua, Perl, Java, JavaScript, Swift • Book author (Beginning iPhone Games Development) • Startup cofounder Objective-C Small, pure superset of C to add OO features to C • (funny syntax was deliberately picked to not • conflict with C, C++ so they can be intermixed) Created in the 80’s, around the same time as C++, • but SmallTalk influences Closest thing to SmallTalk you can get with C • Messaging another core concept of Obj-C • Objective-C Likes late-binding and dynamic dispatch • Pretty small runtime • Pretty efficient introspection & reflection • Not usually a concern unlike in Java, C# • Objective-C Unusual blend of statically compiled C typed • language + dynamic features found in scripting languages Runtime C functions • #import <objc/objc.h> #import <objc/runtime.h> id objc_msgSend(id self, SEL op, …); Cocoa • Huge standard library for Obj-C • Foundation for non-GUI • AppKit for GUI on Mac • UIKit for iOS • Originally from NeXTStep • Foundation + AppKit named Cocoa as pun of Java by Apple • Lots of other frameworks in addition to Cocoa • Some C, some Obj-C • CoreData, CoreGraphics, AudioUnits, OpenGL, etc Cocoa designed for GUI development Exploits a lot of crazy dynamic runtime features of Obj-C under the • hood Responder Chain • Key Value Coding • Key Value Observing • isa-swizzling (aka method swizzling) • Cocoa Bindings • Core Data • NSUndoManager • Interface Builder • LuaObjCBridge (Tom McClean, ~2005) Automatically binds classes & methods at runtime • (no compile time glue code) Simple: Originally 1000-1500 lines including • #ifdefs for GNUStep/Apple Used the only Obj-C 1.0 runtime • No additional things like libffi • Used Lua 5.0 • LuaObjCBridge limitations No subclassing in Lua • Couldn’t handle non-object types • C structs, functions, enums • No automatic memory management • (had to call retain/release/autorelease in Lua code) • No metamethods • (accidental design mistake used lightuserdata) •
Description: