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 -> Bool
true if.doubleValue
contains 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) -> Value
get 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 Value
s
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 = Int32
Count = Int32
LuaFunction = (Lua) -> [Value]
WrappedFunction = ([Value]) -> [Value]
LuaMethod<T> = (T, Lua) -> [Value]
WrappedMethod<T> = (T, [Value]) -> [Value]
LuaInitializer<T> = (Lua) -> T
WrappedInitializer<T> = ([Value]) -> T
Lua()
create a new virtual machine.loadLib([LuaLib])
loads the given standard libraries.globals -> Table
get the global valueTable
run(String) throws -> [Value]
runs aString
as Lua codepush(Value)
pushes aValue
onto the stackpop() -> Value
pops aValue
from the stackcreateTable(Count=0, Count=0) -> Table
creates and returns a newTable
with optional preallocated spacecreateFunction(LuaFunction) -> Function
creates and returns a newFunction
createFunction([Type],WrappedFunction) -> Function
creates and returns a newFunction
that is typechecked internallycreateType<T: LuaConvertible>(T.Type) throws -> CustomType<T>
creates a new Lua type from aLuaConvertible
type 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) -> LuaFunction
wraps aWrappedFunction
to do typechecking internally
stackSize() -> Count
returns the number of items on the Lua stack
- Explicit Garbage Collection
- Rename
CustomType
toCustomClassType
and implementCustomStructType
which is aTable
rather than aUserData
for simpler types - Change how
Function
is implemented to allow them to be released without needing to release the entireLua
machine - Complete
LightUserData
implementation - Expand the capabilities of
CustomType<T>
- Test
UserData
equality - Add
Bool
support - Support for more metamethods