LuaSockets on an embedded platform.

classic Classic list List threaded Threaded
11 messages Options
Reply | Threaded
Open this post in threaded view
|

LuaSockets on an embedded platform.

Michael Broughton
Hello,

I have Lua 5.1 running on my embedded platform (m68k, uClinux) and it
works great. Unfortunately, my platform does not support dynamic loading
of shared libraries because it lacks an MMU.

Now I am trying to add LuaSockets to my platform and I am wondering if
anyone has any tips on how I can do this. Lets just say for now that I
wanted to add the LuaSocket libraries to the lua standalone interpreter
in the same way as all the built in libraries (math, io, string, ...).
Does anyone have any tips on what I need to do to accomplish this? Has
anyone else done this?


Thanks,

Mike
Reply | Threaded
Open this post in threaded view
|

Re: LuaSockets on an embedded platform.

Diego Nehab-3
Hi,

> Now I am trying to add LuaSockets to my platform and I am wondering if anyone
> has any tips on how I can do this. Lets just say for now that I wanted to add
> the LuaSocket libraries to the lua standalone interpreter in the same way as
> all the built in libraries (math, io, string, ...). Does anyone have any tips
> on what I need to do to accomplish this? Has anyone else done this?

Try reading this and let me know if it makes any sense.

     http://lua-users.org/lists/lua-l/2005-12/msg00314.html

Feel free to say it doesn't. :)

Regards,
Diego.
Reply | Threaded
Open this post in threaded view
|

Re: LuaSockets on an embedded platform.

Michael Broughton
It makes perfect sense. I was hoping this would be easy.

Thanks Diego,

PS: Next time I will remember to search before I post!!! :)

Mike



Diego Nehab wrote:

> Hi,
>
>> Now I am trying to add LuaSockets to my platform and I am wondering
>> if anyone has any tips on how I can do this. Lets just say for now
>> that I wanted to add the LuaSocket libraries to the lua standalone
>> interpreter in the same way as all the built in libraries (math, io,
>> string, ...). Does anyone have any tips on what I need to do to
>> accomplish this? Has anyone else done this?
>
> Try reading this and let me know if it makes any sense.
>
>     http://lua-users.org/lists/lua-l/2005-12/msg00314.html
>
> Feel free to say it doesn't. :)
>
> Regards,
> Diego.
>
Reply | Threaded
Open this post in threaded view
|

Re: LuaSockets on an embedded platform.

Eduardo Ochs
Michael Broughton and Diego Nehab wrote:

> > > Now I am trying to add LuaSockets to my platform and I am
> > > wondering if anyone has any tips on how I can do this. Lets just
> > > say for now that I wanted to add the LuaSocket libraries to the
> > > lua standalone interpreter in the same way as all the built in
> > > libraries (math, io, string, ...). Does anyone have any tips on
> > > what I need to do to accomplish this? Has anyone else done this?
> >
> > Try reading this and let me know if it makes any sense.
> >
> >     http://lua-users.org/lists/lua-l/2005-12/msg00314.html
> >
> > Feel free to say it doesn't. :)
>
> It makes perfect sense. I was hoping this would be easy.

It was me who posted the original question, and for me it wasn't so
easy to figure out the details... anyway, I have just created a page
with my build script for a static luasocket and other stuff:

  http;//angg.twu.net/luasocket.html

Cheers,
  Edrx
  http://angg.twu.net/
Reply | Threaded
Open this post in threaded view
|

Re: LuaSockets on an embedded platform.

Michael Broughton
In reply to this post by Diego Nehab-3
Hello again,

I am having some trouble with this and I am not sure why. Here is an
example of what is happening:

/> lua
Lua 5.1  Copyright (C) 1994-2006 Lua.org, PUC-Rio
 > sock = require("socket")
/usr/local/lib/lua/5.1/socket.lua:13: module 'socket.core' not found:
        no field package.preload['socket.core']
        no file './socket/core.lua'
        no file '/usr/local/share/lua/5.1/socket/core.lua'
        no file '/usr/local/share/lua/5.1/socket/core/init.lua'
        no file '/usr/local/lib/lua/5.1/socket/core.lua'
        no file '/usr/local/lib/lua/5.1/socket/core/init.lua'
        no file './socket/core.so'
        no file '/usr/local/lib/lua/5.1/socket/core.so'
        no file '/usr/local/lib/lua/5.1/loadall.so'
        no file './socket.so'
        no file '/usr/local/lib/lua/5.1/socket.so'
        no file '/usr/local/lib/lua/5.1/loadall.so'
stack traceback:
        [C]: in function 'require'
        /usr/local/lib/lua/5.1/socket.lua:13: in main chunk
        [C]: in function 'require'
        stdin:1: in main chunk
        [C]: ?
 > print(package.preload["socket.core"])
function: 0xd0ffc0
 >

The package.preload["socket.core"] is supposed to be the function
"luaopen_socket_core", correct? Or is it supposed to be the result of
calling that function?


Mike




Diego Nehab wrote:

> Hi,
>
>> Now I am trying to add LuaSockets to my platform and I am wondering
>> if anyone has any tips on how I can do this. Lets just say for now
>> that I wanted to add the LuaSocket libraries to the lua standalone
>> interpreter in the same way as all the built in libraries (math, io,
>> string, ...). Does anyone have any tips on what I need to do to
>> accomplish this? Has anyone else done this?
>
> Try reading this and let me know if it makes any sense.
>
>     http://lua-users.org/lists/lua-l/2005-12/msg00314.html
>
> Feel free to say it doesn't. :)
>
> Regards,
> Diego.
>
Reply | Threaded
Open this post in threaded view
|

Re: LuaSockets on an embedded platform.

David Burgess
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.

db

On 1/18/06, Michael Broughton <[hidden email]> wrote:

> Hello again,
>
> I am having some trouble with this and I am not sure why. Here is an
> example of what is happening:
>
> /> lua
> Lua 5.1  Copyright (C) 1994-2006 Lua.org, PUC-Rio
>  > sock = require("socket")
> /usr/local/lib/lua/5.1/socket.lua:13: module 'socket.core' not found:
>         no field package.preload['socket.core']
>         no file './socket/core.lua'
>         no file '/usr/local/share/lua/5.1/socket/core.lua'
>         no file '/usr/local/share/lua/5.1/socket/core/init.lua'
>         no file '/usr/local/lib/lua/5.1/socket/core.lua'
>         no file '/usr/local/lib/lua/5.1/socket/core/init.lua'
>         no file './socket/core.so'
>         no file '/usr/local/lib/lua/5.1/socket/core.so'
>         no file '/usr/local/lib/lua/5.1/loadall.so'
>         no file './socket.so'
>         no file '/usr/local/lib/lua/5.1/socket.so'
>         no file '/usr/local/lib/lua/5.1/loadall.so'
> stack traceback:
>         [C]: in function 'require'
>         /usr/local/lib/lua/5.1/socket.lua:13: in main chunk
>         [C]: in function 'require'
>         stdin:1: in main chunk
>         [C]: ?
>  > print(package.preload["socket.core"])
> function: 0xd0ffc0
>  >
>
> The package.preload["socket.core"] is supposed to be the function
> "luaopen_socket_core", correct? Or is it supposed to be the result of
> calling that function?
>
>
> Mike
>
>
>
>
> Diego Nehab wrote:
> > Hi,
> >
> >> Now I am trying to add LuaSockets to my platform and I am wondering
> >> if anyone has any tips on how I can do this. Lets just say for now
> >> that I wanted to add the LuaSocket libraries to the lua standalone
> >> interpreter in the same way as all the built in libraries (math, io,
> >> string, ...). Does anyone have any tips on what I need to do to
> >> accomplish this? Has anyone else done this?
> >
> > Try reading this and let me know if it makes any sense.
> >
> >     http://lua-users.org/lists/lua-l/2005-12/msg00314.html
> >
> > Feel free to say it doesn't. :)
> >
> > Regards,
> > Diego.
> >
>
Reply | Threaded
Open this post in threaded view
|

Re: LuaSockets on an embedded platform.

Diego Nehab-3
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.
Reply | Threaded
Open this post in threaded view
|

Re: LuaSockets on an embedded platform.

Michael Broughton
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.
>
Reply | Threaded
Open this post in threaded view
|

Re: LuaSockets on an embedded platform.

David Burgess
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 <[hidden email]> 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.
> >
>
Reply | Threaded
Open this post in threaded view
|

Re: LuaSockets on an embedded platform.

Michael Broughton
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 Lua.org, 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?

Mike



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
>
> 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 <[hidden email]> 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.
>>>
>>>      
>
>  
Reply | Threaded
Open this post in threaded view
|

Re: LuaSockets on an embedded platform.

Michael Broughton
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 Lua.org, 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?
>
> Mike
>
>
>
> 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
>>
>> 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 <[hidden email]> 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.
>>>>
>>>>      
>>
>>  
>