LuaSocket and LuaFileSystem for Windows
Posted: Tue May 12, 2015 9:50 pm
Hi guys,
External Lua C modules aren't that easy to compile on Windows so I went ahead and compiled LuaFileSystem and LuaSocket so that they can be used with Octane. I didn't bother with Linux and OSX because on those systems, the modules can be installed easily via the LuaRocks package manager.
First you need to unzip the file, it's very important to keep the directory structure intact because LuaSocket relies on this structure. Then, in your script you need to make sure that these modules can be found by
Here's a minimal example just to show how to load the libraries:
And here's the zipfile with the libraries:
We can add more libraries later (if they are well-supported and maintained). Obviously when don't make any guarantees about all this code and don't give any support. If anybody is interested in compiling the libraries himself, PM me and I will happily provide you with the Visual Studio project.
edit: Some users requested the Visual Studio project so I've attached it here. The solution was created in VS 2010. The archive contains:
cheers,
Thomas
External Lua C modules aren't that easy to compile on Windows so I went ahead and compiled LuaFileSystem and LuaSocket so that they can be used with Octane. I didn't bother with Linux and OSX because on those systems, the modules can be installed easily via the LuaRocks package manager.
First you need to unzip the file, it's very important to keep the directory structure intact because LuaSocket relies on this structure. Then, in your script you need to make sure that these modules can be found by
require
. You do this by modifying the package.path
and package.cpath
variables (you can read more about them here).Here's a minimal example just to show how to load the libraries:
- Code: Select all
print("------------------ LuaFileSytem -------------------")
-- make sure the lfs.dll can be found
package.cpath = package.cpath .. ";C:\\tmp\\lualibs_windows\\luafilesystem\\?.dll"
require("lfs")
print(lfs._VERSION)
-- execute some code from the LuaFileSystemLib
print(lfs.currentdir())
for it,obj in lfs.dir(lfs.currentdir()) do
print(it)
end
print("------------------ LuaSocket -------------------")
-- LuaSocket is distributed as a dll (core.dll) and a set of wrapper lua scripts, we need to make sure that all these
-- can somehow be found by lua by fudging package.cpath and package.path
package.cpath = package.cpath .. ";C:\\tmp\\lualibs_windows\\luasocket\\mime\\?.dll"
package.cpath = package.cpath .. ";C:\\tmp\\lualibs_windows\\luasocket\\?.dll"
package.path = package.path .. ";C:\\tmp\\lualibs_windows\\luasocket\\?.lua"
require("socket")
print(socket._VERSION)
http = require("socket.http")
-- request our home page via the socket library
local ourHome = http.request("http://render.otoy.com")
print(ourHome)
And here's the zipfile with the libraries:
We can add more libraries later (if they are well-supported and maintained). Obviously when don't make any guarantees about all this code and don't give any support. If anybody is interested in compiling the libraries himself, PM me and I will happily provide you with the Visual Studio project.
edit: Some users requested the Visual Studio project so I've attached it here. The solution was created in VS 2010. The archive contains:
- The Visual Studio 2010 files.
- The header files and pre-compiled binaries for LuaJIT 2.0.2 (they are a dependency for all the other projects).
- Source code for Lua Filesystem version 1.6.3
- Source code for Lua Sockets 2.0.2
cheers,
Thomas