Use it can be easily applied the Lua script on iOS, and provides a powerful interactive features to be extended
- Clone the source to local disk.
- Drag the LuaScriptCore.xcodeproj to your project.
- Click your project root node in Xcode, and go to the Build Phases panel in right panel;
- Add LuaScriptCore as dependency library in Target Dependencies section.
- Add LuaScriptCore.a in Link Binary With Libraries section.
- Now,you can import the LuaScriptCore/LuaScriptCore.h header in your code then use it.
LSCContext *context = [[LSCContext alloc] init];
LSCValue *value = [self.context callMethodWithName:@"add"
arguments:@[[LSCValue integerValue:1000],
[LSCValue integerValue:24]]];
NSLog(@"result = %@", [value toNumber]);
In ObjC
[self.context registerMethodWithName:@"getDeviceInfo" block:^LSCValue *(NSArray *arguments) {
NSMutableDictionary *info = [NSMutableDictionary dictionary];
[info setObject:[UIDevice currentDevice].name forKey:@"deviceName"];
[info setObject:[UIDevice currentDevice].model forKey:@"deviceModel"];
[info setObject:[UIDevice currentDevice].systemName forKey:@"systemName"];
[info setObject:[UIDevice currentDevice].systemVersion forKey:@"systemVersion"];
return [LSCValue dictionaryValue:info];
}];
In lua
local tbl = getDeviceInfo();
In lua
function add (a, b)
return a+b;
end
In ObjC
LSCValue *value = [self.context callMethodWithName:@"add"
arguments:@[[LSCValue integerValue:1000],
[LSCValue integerValue:24]]];
NSLog(@"result = %@", [value toNumber]);