LuaThread is a delicate Lua extension library that requires you to completely recompile the Lua distribution. We know of no general, clean and automatic way of doing this. Therefore, you will have to modify yourself the project used to create the Lua distribution you plan to use in conjunction with LuaThread.
To ensure that LuaThread makes it into the Lua core, luathread.h should be included in every module present in the Lua distribution. This can be done by redefining the LUA_USER_H preprocessor macro present in the standard lua.h file. If you have trouble redefining LUA_USER_H externally (with Microsoft Visual Studio, for instance), don't be shy and modify lua.h by hand. Feel free to place luathread.h, pt.h and srm.h in the Lua distribution include directory to simplify your life. Rebuild the Lua library from scratch for the changes to take effect.
It doesn't matter how you link everything together as long as in the end all LuaThread modules get linked with your application and the Lua library (on Unix systems you will also need the Pthreads library). To initialize the client side of LuaThread, invoke luaopen_thread function on a given Lua state. If you are building the Lua interpreter itself, there is a handy preprocessor macro for that purpose: LUA_EXTRALIBS.
LuaThread uses the new package proposal for Lua 5.1. All Lua library developers are encouraged to update their libraries so that all libraries can coexist peacefully and users can benefit from the standardization and flexibility of the standard.
The proposal was considered important enough by some of us to justify early adoption, even before release of Lua 5.1. Thus, a compability module compat-5.1 has been released in conjunction with Roberto Ierusalimschy and The Kepler Project team. It implements the Lua 5.1 package proposal on top of Lua 5.0.
Here we will only describe the standard distribution. If the standard doesn't meet your needs, we refer you to the Lua discussion list, where any question about the package scheme will likely already have been answered.
The standard distribution reserves a directory to be the root of the libraries installed on a given system. Let's call this directory <ROOT>. On my system, this is the /usr/local/share/lua/5.0 directory. Here is the standard LuaThread distribution directory structure:
<ROOT>/compat-5.1.lua <ROOT>/thread/queue.lua
In order for the interpreter to find all LuaThread components, two environment variables need to be set. The first environment variable tells the interpreter to load the compat-5.1.lua module at startup:
LUA_INIT=@<ROOT>/compat-5.1.luaThe other environment variables instruct the compatibility module to look for extension modules in the appropriate directories and with the appropriate filename extensions.
LUA_PATH=<ROOT>/?.lua;?.lua
With the above setup, and an interpreter linked to a LuaThread enabled library, it should be easy to use LuaThread. Just fire the interpreter and use the require function to gain access to the API:
Lua 5.0.2 Copyright (C) 1994-2004 Tecgraf, PUC-Rio > thread = require("thread") > print(thread.VERSION) --> LuaThread 1.0 (alpha)