在Cocoa中使用Lua
作者: Cocoa China [去开发讨论区讨论本文] [本文永久地址]
15
Jul
Lua是一种非常好的脚本语言,最常用的是在游戏中。目前最强悍的MMORPG:World of Warcraft魔兽世界的UI插件便是用Lua写成。
LuaCore是一个Objective-C框架,专门用于在Cocoa中使用Lua脚本。同时,它还可以将Lua的数据直接转化成Objective-C的对象,更方便使用。
这里是一个例子,演示如何使用LuaCore:
-
#import <foundation /Foundation.h>
-
#import <luacore /LuaCore.h>
-
-
int main (int argc, const char * argv[]) {
-
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
-
-
LCLua *lua = [LCLua readyLua];
-
[lua runBuffer:@"print('hello world')"];
-
-
[pool release];
-
return 0;
-
}
-
</luacore></foundation>
这里还有一个简单的Lua Bridge实现,如果有兴趣也可以看一下。
发表评论