Earlier today I was playing around with Lua and luarocks on my laptop (which happens to be a MacBook Pro). I thought maybe I’d try re-writing telechat in Lua with the LuaSocket package. After I’d installed Lua 5.1.4 via mac ports along with luarocks:
$ sudo port -v install lua luarocks
I installed LuaSocket.
$ sudo luarocks install luasocket
I was under the mistaken impression that when I tried to run some example code, the ENVIRONMENT would be setup and functioning properly. Unfortunately this was not the case:
$ lua Lua 5.1.4 Copyright (C) 1994-2008 Lua.org, PUC-Rio > require "sockets" /opt/local/share/lua/5.1/luarocks/require.lua:256: module 'sockets' not found: no field package.preload['sockets'] no file './sockets.lua' no file '/opt/local/share/lua/5.1/sockets.lua' no file '/opt/local/share/lua/5.1/sockets/init.lua' no file '/opt/local/lib/lua/5.1/sockets.lua' no file '/opt/local/lib/lua/5.1/sockets/init.lua' no file './sockets.so' no file '/opt/local/lib/lua/5.1/sockets.so' no file '/opt/local/lib/lua/5.1/loadall.so' stack traceback: [C]: in function 'plain_require' /opt/local/share/lua/5.1/luarocks/require.lua:256: in function 'require' stdin:1: in main chunk [C]: ?
After some investigation I’d realized that the LUA_PATH wasn’t set up by the packages that were installed. Since I’d installed the LuaSocket package as the administrator (with the sudo command). I needed to include the system-wide path to the rocks libraries. I did this for my user only by editing my .kshrc file. If I’d wanted to do the same thing in bash I could have used .bshrc or .bashrc. To do it for every user of the system I could have use /etc/profile and /etc/login. In any case I put in this line:
export LUA_PATH="/opt/local/share/lua/5.1//?.lua;/opt/local/lib/luarocks/?.lua;;"
After that was included everything ran fine (don’t forget to reload your environment.
lua: /usr/local/share/lua/5.1//soap/http.lua:7: module ‘luasocket’ not found:
no field package.preload['luasocket']
no file ‘/usr/local/share/lua/5.1//luasocket.lua’
no file ‘/usr/share/lua/5.1/soap/luasocket.lua’
no file ‘/usr/share/lua/5.1/socket/luasocket.lua’
no file ‘./luasocket.lua’
no file ‘/usr/local/share/lua/5.1/luasocket.lua’
no file ‘/usr/local/share/lua/5.1/luasocket/init.lua’
no file ‘/usr/local/lib/lua/5.1/luasocket.lua’
no file ‘/usr/local/lib/lua/5.1/luasocket/init.lua’
no file ‘/usr/local/lib/lua/5.1//luasocket.so’
no file ‘/usr/local/lib/lua/5.1/socket/luasocket.so’
no file ‘./luasocket.so’
no file ‘/usr/local/lib/lua/5.1/luasocket.so’
no file ‘/usr/local/lib/lua/5.1/loadall.so’
stack traceback:
[C]: in function ‘require’
/usr/local/share/lua/5.1//soap/http.lua:7: in main chunk
[C]: in function ‘require’
calSer.lua:1: in main chunk
[C]: ?
I am getting this error even i followed the correct path
Please get the solution so that i can work
Thanks
Kishore.
What OS are you using? If you’re on OSX how did you install LUA; with macports, fink, or pkgsrc?
I need more information before I can help you.
Thanks Cliff for the reply.
I am using Mac OSX and i install LUA5.1.4 and using pkgsrc I installed.I followed the above solution you have mentioned for sockets it is working fine.
But when I run test.lua file which comes from luasoap I am getting the error that
ua: /usr/local/share/lua/5.1//soap/http.lua:7: module ‘luasocket’ not found:
Please let me know the solutions it is urgent.
Thanks,
Kishore
Unfortunately luasoap wasn’t setup as a rocks package. The installation isn’t quite as straight forward as other packages. Without being on your box the best thing I can suggest is to try loading the test file with lua -lluasockets or make a copy of test.lua and modify it to explicitly set package.path. I know neither of these are ideal solutions but they should get you up an running without having to go back an forth with me asking you a million more question about your set up.
If you can invoke lua -lluasockets with no problem then you should be able to get the test.lua script running with no problem.
Best of luck, please let me know if there is something more I can do for you.
btw.. you might want to ask in #lua on freenode (IRC). I’m often in there (gcw) and the people there are very knowledgeable.
Hey Thanks,
I need to know whether any examples are present for luasoap so that i can have a better understanding.
Thanks,
Kishore
Sorry I’ve never used luasoap before.. I’m sure that you can google examples or ask in either IRC or on the mailing list. Wish I could be of more help.
Hey thanks Cliff for the reply
i found solution for the luasoap it is working fine here
I worked on the link below to find the solution This link is help full
http://lua-users.org/lists/lua-l/2009-10/msg00548.html.
Thanks & bye.
Kishore
Have you been able to get lua-socket to run on Snow Leopard?
I get symbol not found errors against the core.so shared library, and a good hour of Googling has not helped.
it’s been working for me with no problem. A few questions for you
1) are you using the MacPorts installation
2) if so did you go through the migration steps?
3) are you using luarocks 1.x or 2.x?