How to embed Xavante in a device

39 views
Skip to first unread message

Daniel Diniz

unread,
Mar 6, 2017, 11:11:40 AM3/6/17
to Kepler Developers
Hello,

My goal is to be able to run a completely lua based web server from an OpenWRT based device, and I thought Xavante would be my best bet of achieving this. 
The problem is, I am also at the same time learning the basics of Lua and how to call it from C code and whatnot, and have been fighting with stuff that still does not involve embedded development at all, such as simply calling my Xavante config lua script (same as the example in their website). 

I know Xavante has dependencies with 3 other modules (namely LuaSocket, Copas, LuaFileHandler), and I have been getting dynamic libraries linking problems even while trying to run it on my machine, not even on target yet. 

I'm currently trying (from my "helloWorld.c" test file):

luaL_loadfile(L, "xavante.lua");

lua_pcall
(L, 0, 0, 0);

where xavante.lua configures and starts xavante. From this command, I get dynamic linking problems, and it prints:

lua call error: error loading module 'lfs' from file '/usr/local/lib/lua/5.3/lfs.so':
                     /usr/local/lib/lua/5.3/lfs.so: undefined symbol: lua_gettop
 
Xavante starts normally if I just run:
$ lua xavante.lua


Am I taking the right approach for dealing with this? Should I pre-compile the dynamic libraries and put them as .so files in my device, or should I find a way to link them statically? Is there another way to load dynamic libraries from .c files?

I've ran out of resources to solve this, so thank you very much, in advance, for any help,

Regards,

Daniel

Daniel Diniz

unread,
Mar 9, 2017, 3:52:56 AM3/9/17
to Kepler Developers
A quick update here, I managed to compile it in my host machine and also for my target.
I found some ready-made OpenWRT makefiles for the shared libraries (luasocket and luafilesystem) and even one for Xavante itself.

I still can't run my xavante.lua script, it seems to look for the libraries in the wrong places, so I'm trying to figure out what I did wrong. If I try to start the Xavante web server from my target device, I get the following:

lua call error: xavante.lua:1: module 'xavante.filehandler' not found:
        no field package.preload['xavante.filehandler']
        no file '/usr/local/share/lua/5.3/xavante/filehandler.lua'
        no file '/usr/local/share/lua/5.3/xavante/filehandler/init.lua'
        no file '/usr/local/lib/lua/5.3/xavante/filehandler.lua'
        no file '/usr/local/lib/lua/5.3/xavante/filehandler/init.lua'
        no file './xavante/filehandler.lua'
        no file './xavante/filehandler/init.lua'
        no file '/usr/local/lib/lua/5.3/xavante/filehandler.so'
        no file '/usr/local/lib/lua/5.3/loadall.so'
        no file './xavante/filehandler.so'
        no file '/usr/local/lib/lua/5.3/xavante.so'
        no file '/usr/local/lib/lua/5.3/loadall.so'
        no file './xavante.so'

Mauricio Henrique Bomfim

unread,
Mar 9, 2017, 6:22:32 AM3/9/17
to kepler-...@googlegroups.com
Hi,

you have to set variables package.path and package.cpath with the
right places where you keep your libraries.

See http://lua-users.org/wiki/PackagePath

[]s

Mauricio
> --
> You received this message because you are subscribed to the Google Groups
> "Kepler Developers" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to kepler-projec...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Daniel Diniz

unread,
Mar 15, 2017, 8:29:17 AM3/15/17
to Kepler Developers
Hello,

Thanks Mauricio, it helped my application locate the libraries, but now I get a Segmentation fault from the require statements.
Even though the right libraries have been compiled and set at the right place, my lua application can't load them through require.

These calls:
  1 local hfile = require "xavante.filehandler"
 
2 local hcgi = require "xavante.cgiluahandler"
 
3 local hredir = require "xavante.redirecthandler"


all seg fault now that the libraries are at the right place, when called from my C application with
 luaL_loadfile(L, "xavante.lua");

No idea why... on my host this works ok!
Reply all
Reply to author
Forward
0 new messages