[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: [ANN] LuaSwift - Swift bindings for Lua
- From: Tom Sutcliffe <tomsci@...>
- Date: Sat, 16 Sep 2023 22:24:30 +0100
Hi list,
I wrote some Swift bindings for Lua for a project a while back, which I've finally released as a separate project. If you need to integrate Lua into a Swift project, check out:
https://github.com/tomsci/LuaSwift
This wraps Lua up in a Swift package and adds Swift type-safe wrappers around the Lua C APIs.
It has several features that I think improve on existing libraries that do roughly the same thing, in particular the fact that all the Swift-y stuff is implemented as extensions to (the Swift equivalent of) `lua_State*`, meaning Swift implementations of lua_CFunctions have access to all the Swift type-safe APIs that top-level Swift functions calling into Lua do, as well as the ability to freely mix use of the standard Lua C API with LuaSwift calls. There is also support for bridging Swift data types as userdata with metatables (in a type- and ARC-safe manner), and some rather funky type inferencing for converting Lua datatypes to their Swift equivalents.
LuaSwift should run on any platform Swift does (macOS, iOS, linux), and in the spirit of Lua's minimal dependencies, it can be compiled without even requiring Foundation. I reluctantly added a build-time dependency on the Swift documentation builder package so I could generate the online documentation :-) (I may try to refactor that in future to not place that burden on downstream users of the package...)
As an aside, the genesis of this project came from arguing with a friend that a project really didn't need to have its own domain-specific language and that Lua was a better choice (and could do everything required). The net result was a lot of code being deleted and Lua (via LuaSwift) being used instead. Having missed the 30th anniversary announcement, I'd like to add my thanks to the Lua team for providing us with such a wonderfully flexible language. Over the last 10+ years I've used it on microcontroller boards with 96KB of RAM, PCs, Macs, iPhones, set-top boxes, remote controls... for everything from 5-minute prototypes to commercial products. This is I think the 2nd time I've used it to replace an existing domain-specific language that had reached its limits (can we please stop inventing more of these, industry?) which is a testament to Lua's adaptability and the thought that went into the language. In many aspects it is my go-to example on good language design. So congratulations to the Lua team on reaching this milestone!
Cheers,
Tom