Grease is a networking library for lua, using LuaSocket, and optionally Lua-ENet. It was designed to operate within the LÖVE framework, but also works without it.
Grease has been built with classes in mind, and for that purpose it uses Class Commons, a compatibility layer between lua class libraries. To help people who are not interested in it, it also comes with a minimal implementation as a fallback.
Grease comes with several base types, and their implementations. These are:
Note that you should probably not be using either of the base classes (grease.Client
or grease.Server
), nor deriving from them, unless you want to implement a new low-level protocol (and you don’t.) You should also probably not be deriving from any of the other classes, instead just instantiating them.
Sets the ping settings for this client.
Connect to a server.
Disconnect from the server, if connected.
Send data to the server.
Receive data from the server.
Do all time-based stuff, call callbacks etc.
WARNING: Due to a bug, this function is called setoption
for tcp and enet. Set an option for this socket. * option: One of:
* "broadcast": Allow connectivity with broadcast addresses, may fail.
Used in connect/disconnect messages, should match the server’s.
WARNING: The handshake shouldn’t occur in normal (other) messages.
Called whenever a client receives data, and is subsequently updated, meant to be overridden by user.
Sets the ping settings used on this server.
Start listening, allows people to connect.
Do all time-based stuff, call callbacks etc.
Send data to a/all client(s).
Get data from a (random) client.
Used in connect/disconnect messages, should match the client’s.
WARNING: The handshake shouldn’t occur in normal (other) messages.
Called whenever a server receives data, and is subsequently updated, meant to be overridden by user.
Called whenever a client connects to the server, and is subsequently updated, meant to be overridden by user.
Called whenever a client disconnects from the server, and is subsequently updated, meant to be overridden by user.
Client IDs are used to identify specific clients connected to a server, they are completely implementation-defined and you should only use obtained Client IDs either as unique indexes for your storage (but take care to not prevent garbage collection), or as input for Grease’s functions. Any Client IDs given to Grease must also have been obtained from it.