A Swift wraper for Lua 5.2.4
Not every feature is implemented, and the API is not yet stable Feel free to open a new issue or pull request
Lua values are wrapped within the Value protocol when brought into Swift
Swift's String is used to represent Lua strings
The Number class represents a numeric value within Lua. It supports conversion to Int, UInt32, and Double as well as comparisons with those types.
.intValue -> Int.uintValue -> UInt32.doubleValue -> Double.isInt -> Booltrue if.doubleValuecontains no decimal places
Swift's UnsafeMutablePointer is used to represent Lua lightuserdatas
The Table class represents a table within Lua. It supports getting and setting values.
subscript(Value) -> Valueget and set valuesforEach(body: (TableKey, Value) -> Void)iterate over all key/value pairs intoDictionary() -> [TableKey : Value]fetches all of the key/value pairs from the Lua VM and returns a Dictionary
The Function class represents a Lua closure. It supports calling with a list of Values
call([Value]) -> [Value]call the function with the arguments
It is possible to bring Swift types into Lua by creating a CustomType<T> which gives access to the new type's metatable and statictable
Represents a nil value on the stack
Index = Int32Count = Int32LuaFunction = (Lua) -> [Value]WrappedFunction = ([Value]) -> [Value]LuaMethod<T> = (T, Lua) -> [Value]WrappedMethod<T> = (T, [Value]) -> [Value]LuaInitializer<T> = (Lua) -> TWrappedInitializer<T> = ([Value]) -> T
Lua()create a new virtual machine.loadLib([LuaLib])loads the given standard libraries.globals -> Tableget the global valueTablerun(String) throws -> [Value]runs aStringas Lua codepush(Value)pushes aValueonto the stackpop() -> Valuepops aValuefrom the stackcreateTable(Count=0, Count=0) -> Tablecreates and returns a newTablewith optional preallocated spacecreateFunction(LuaFunction) -> Functioncreates and returns a newFunctioncreateFunction([Type],WrappedFunction) -> Functioncreates and returns a newFunctionthat is typechecked internallycreateType<T: LuaConvertible>(T.Type) throws -> CustomType<T>creates a new Lua type from aLuaConvertibletype and returns its CustomTypewrap<T: LuaConvertible>([Type], @escaping WrappedInitializer<T>) -> LuaInitializer<T>wraps aWrappedInitializer<T>to do typechecking internallywrap<T: LuaConvertible>([Type], @escaping WrappedMethod<T>) -> LuaMethod<T>wraps aWrappedMethod<T>to do typechecking internallywrap([Type], @escaping WrappedFunction) -> LuaFunctionwraps aWrappedFunctionto do typechecking internally
stackSize() -> Countreturns the number of items on the Lua stack
- Explicit Garbage Collection
- Rename
CustomTypetoCustomClassTypeand implementCustomStructTypewhich is aTablerather than aUserDatafor simpler types - Change how
Functionis implemented to allow them to be released without needing to release the entireLuamachine - Complete
LightUserDataimplementation - Expand the capabilities of
CustomType<T> - Test
UserDataequality - Add
Boolsupport - Support for more metamethods