lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On 30.10.2011 12:33, Jeff Smith wrote:


Hi Just started having my first look at Lua Socket, I am puzzled by the required files, I am probably missing something obvious but local base = _G
local string = require("string")
local math = require("math")
local socket = require("socket.core")
module("socket") I couldnt figure out what code the local socket = require("socket.core") was pulling in ? I thought that socket.core was a folder hierarchy such as \socket\core.lua for example ? Anyway I trawled around the luasocket folder looking for core.lua or core.dll and couldnt spot anything at all.

There should be. Mine is here:
/usr/lib/lua/5.1/socket/core.so

There's another possibility: By default Lua also looks in socket.dll for the function luaopen_socket_core. If there is no socket\core.dll, it might be in socket.dll.


> Also I wasnt sure what the point of the string and math lines were for ?

The module("socket") call replaces the global environment with a fresh empty table, so no globals are accessible after that. Therefore, luasocket makes sure that the necessary modules are available and creates local aliases for them. I use something like

local string = assert( string )

for this, but I guess require gives better error messages.

They are pulled in as default libraries by Lua anyway ?

This is true for the standalone Lua interpreter. If you embed Lua into your own program you are free to add or leave out any Lua library you want. For instance, the math module only makes sense if you have floating point Lua numbers available.

HTH,
Philipp