LuaSocket
Network support for the Lua language

home · download · introduction · reference


The LuaSocket namespace

The socket namespace contains the namespace tables for all LuaSocket modules as well as function that didn't belong in any specific module, functions that are so commonly used that deserve a shortcut and a few constants.

socket.debug

This constant is set to true if the library was compiled with debug support.

socket.protect(function)

Converts a function that throws exceptions into a safe function.

Function is a function that calls try to throw exceptions.

The function an equivalent function that instead of throwing exceptoins, returns nil followed by an error message.

socket.try(ret1, ret2 ... retN)

Throws an exception in case of error.

Ret1, ret2 ... retN can be arbitrary arguments, but are usually the return values of a function call that nested with the call to try.

The function returns ret1, ret2 ... retN if ret1 is not nil. Otherwise, calls error passing ret2.

-- connects or throws an exception with the appropriate error message
c = socket.try(socket.connect("localhost", 80))

socket.version

This constant has a string describing the current LuaSocket version.