[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Lua modules and packaging - splitting big stuff into smaller pieces
- From: Marius Kjeldahl <marius@...>
- Date: Mon, 21 Jun 2004 12:51:08 +0200
Although not an experienced Lua hacker by any counts, I've read throught the
Wiki, the discussions on this list and followed the release of
luasocket-2.0-beta. I have a small toy-project which ran fine with
luasocket-2.0-alpha, but after the release of the beta I am trying to updated
it both to work with the latest release AND to learn about the proper way of
packaging modules "lua-style".
I've written more about what I have done to get it up and running at the end
of this email, but my real question is:
* What is the general advice on how to package your own lua source code
modules?
I tried doing it the "luasocket" style way, by starting my module
(ModuleName.lua) with:
local ModuleName = {}
_LOADED["ModuleName"] = ModuleName
function ModuleName.test ()
print ("Hello world!")
end
however, if I try from my "main" lua program the following:
require ("lua.lua") -- Use modified require defintion from luasocket
local mymod = require ("ModuleName")
print (mymod)
mymod.test ()
I get the following:
table: 0x807bec0
lua: Main.lua:29: attempt to call field `test' (a nil value)
stack traceback:
Main.lua:29: in function `Main'
<command line>:1: in main chunk
[C]: ?
The print line shows that mymod is a valid table, but still the "test"
function is a nil value, and I am not sure why.
If somebody have any pointers to where I can get the advice on how to do this,
please let me know. Yes, I have ordered the book...
And finally, does anybody have a nice "Dumper" function ready, similar to
perl's Data::Dumper module? That would probably help me figuring out what is
hidden behind all these tables and be nice for debugging.
Regards,
Marius K.
COMMENTS ABOUT WHAT I HAVE DONE BELOW:
I'm pretty sure I've gotten luasocket-2.0-beta up and running fine. The
"advice" on the luasocket documentation pages basically said stuff everything
into one directory and it should work. While this might be a good initial
advice, it gives me little to no clue on how I am supposed to be doing it
"the proper way". With some trial and error, I managed to get luasocket
running from it's own directory, and with my own code in it's own place. If
others wonder, this is basically what I had to do:
In the "main" lua executable, I start with:
LUA_PATH = "/usr/local/lua/luasocket/?;/usr/local/lua/luasocket/?.lua;?;?.lua"
LUA_PATHLIB = "/usr/local/lua/luasocket/libluasocket.so"
require ("lua.lua")
This bascially tells lua to add /usr/local/lua/luasocket to the list of
directories to look for lua modules (at least when using the modified require
function that comes with lua.lua). Furthermore, it says exactly what
(including location) luasocket shared library I want to use.