lua-users home
lua-l archive

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

Never mind. I cleaned and recompiled everything and it works now.

Thanks for the help guys.

Michael Broughton wrote:
It definitely helps. Thanks.

I am still having a problem, however. I am able to use the socket module by itself. I used it to start a simple echo server (from the LuaSocket docs). But I am having trouble with the other modules:

/> lua
Lua 5.1  Copyright (C) 1994-2006, PUC-Rio
> h = require("socket.http")
error loading module 'socket' from file '/usr/local/share/lua/5.1/socket.lua':
       /usr/local/share/lua/5.1/socket.lua:1: unexpected symbol
stack traceback:
       [C]: ?
       [C]: in function 'require'
       /usr/local/share/lua/5.1/socket/http.lua:11: in main chunk
       [C]: in function 'require'
       stdin:1: in main chunk
       [C]: ?

Any suggestions?


D Burgess wrote:
That was not a good reply from me.

loader.preload["socket.core"] = afunction

When you execute require"socket.core" the function at this
table entry is executed. To quote the manual
"To find a loader, first require queries package.preload[modname].
If it has a value, that value (which should be a function) is the loader."

So in your case, I believe that you need

loader.preload["socket.core"] =  luaopen_socket_core


  lua_getfield(L, LUA_GLOBALSINDEX, "package");
  if (!lua_istable(L, -1)) {  /* no such field? */
    luaL_error(L, LUA_QL("package") " must be a table");
      return 0;
  lua_getfield(L, -1, "preload");
  if (!lua_istable(L, -1)) {  /* no such field? */
    luaL_error(L, LUA_QL("package.preload") " must be a table");
      return 0;
  lua_pushcfunction(L, luaopen_socket_core);
  lua_setfield(L, -2, "socket.core");

Hope this helps.


On 1/18/06, Michael Broughton <> wrote:
Unfortunately, DB's reply has me confused. Let me see if I have this
right: package.preload["socket.core"] should be a function that returns
the function luaopen_socket_core when it is called?


Diego Nehab wrote:

the result of calling the function. That is, what is in the preload
table entry should return a lua_cfunction that is
My apologies... Looks like my previous post was wrong. No wonder
people didn't manage to get this working.