lua-users home
lua-l archive

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


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

e.g.

  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.

DB

On 1/18/06, Michael Broughton <mbobowik@telusplanet.net> 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?
>
> Mike
>
>
>
> Diego Nehab wrote:
> > Hi,
> >
> >> the result of calling the function. That is, what is in the preload
> >> table entry should return a lua_cfunction that is
> >> luaopen_socket_core.
> >
> > My apologies... Looks like my previous post was wrong. No wonder
> > people didn't manage to get this working.
> >
> > []s,
> > Diego.
> >
>