LuaCore, a simple Cocoa wrapper for Lua 5.1


Download: luacore.tgz, version 0.2

Browse: luacore


What is it?

LuaCore is an Objective-C framework for running Lua scripts. Even better than that, it includes a bridge so that you can pass in Objective-C objects, and work with them in the Lua environment. You can call functions and methods and all kinds of other crazy things.

Everything needed for "Hello world":

#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;
}
Yes, it's that easy.

Pushing values in:

LCLua *lua = [LCLua readyLua];
[lua pushAsLuaString:@"this is the value of s" withName:@"s"];
[lua pushDictionaryAsTable:[NSDictionary dictionary] withName:@"d"];
[lua pushGlobalObject:self withName:@"myObject"];
[lua runBuffer:@"print(s)"];
[lua runBuffer:@"print(myObject:description())"];


Calling functions

[lua callFunction:@"addFour" withArg:[NSNumber numberWithInt:5]]


Questions or Patches?

Send them along!
gus@flyingmeat.com