Lua是一种非常好的脚本语言,最常用的是在游戏中。目前最强悍的MMORPG:World of Warcraft魔兽世界的UI插件便是用Lua写成。

LuaCore是一个Objective-C框架,专门用于在Cocoa中使用Lua脚本。同时,它还可以将Lua的数据直接转化成Objective-C的对象,更方便使用。

这里是一个例子,演示如何使用LuaCore:

 

  1. #import <foundation /Foundation.h>
  2. #import <luacore /LuaCore.h>
  3.  
  4. int main (int argc, const char * argv[]) {
  5.     NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
  6.  
  7.     LCLua *lua = [LCLua readyLua];
  8.     [lua runBuffer:@"print('hello world')"];
  9.  
  10.     [pool release];
  11.     return 0;
  12. }
  13. </luacore></foundation>

 

这里还有一个简单的Lua Bridge实现,如果有兴趣也可以看一下。