在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):weyhan/lua4swift开源软件地址(OpenSource Url):https://github.com/weyhan/lua4swift开源编程语言(OpenSource Language):C 92.9%开源软件介绍(OpenSource Introduction):lua4swiftHigh-level (convenient) Lua bindings for Swift
What do you mean by "convenient"?It's meant to be used to add extensibility to your OS X application. The idea is, you already wrote an app and just want to make it extensible in Lua, so you just throw this library in, and start wrapping your app's internal types and functions to work with Lua, and start running your user's Lua code. What do you mean by "high-level"?This library doesn't let you use the traditional "Lua stack". Instead, you operate with Swift values: When you create a Lua function, you really give it a Swift function which this library wraps up. That function takes an array of values which you then extract and use. When you're done, you return an array of values. When you want to create values, you don't push them onto a stack, you create them using methods on your These values are either of types common to both Lua and Swift, such as String and Boolean, or a Swift wrapper around a Lua type, such as Function and Number. This means returning values from your custom Lua functions can be as natural as Lua's Because of all this, this library makes some trade-offs that make it not as optimal with speed and memory as it could have been. What do you mean by "Swift"?(ಠ_ಠ) What do you mean by "bindings"?Like, it wraps Lua's C API so you can use Lua from Swift. That kind of bindings. Not the other kind. And not the other other kind. Binding has too many meanings. Maybe we should like, use more better words when saying about stuff? Show us an example already!Okay fine. Here's a port of the function in Roberto's Lua book to split a string by a string delimiter: let vm = Lua.VirtualMachine()
let stringxLib = vm.createTable()
stringxLib["split"] = vm.createFunction([String.arg, String.arg]) { args in
let (subject, separator) = (args.string, args.string)
let fragments = subject.componentsSeparatedByString(separator)
let results = vm.createTable()
for (i, fragment) in enumerate(fragments) {
results[i+1] = fragment
}
return .Value(results)
}
vm.globals["stringx"] = stringxLib Given this, you could do this in Lua: stringx.split('hello world', ' ') -- returns {"hello", "world"} License
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论