lua-users home
lua-l archive

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


> could u tell me the correct way to build a module for lua like LuaXML and luasocket?maybe i leak some important steps while building them.
> if i really cannot make them work,i will write a simple module by myself.
>
> My platform is WinCE5.0

IMO there's no "correct way", it is only the "prefered way".

lua is an embedded language and the nature in embedded world is you
may need to re-compile on every platform and you may need to tune your
make script on every different platform.

The sample is: if you know how to build lua then you should know how
to build luaxml, let's see my lua build:

poet:~/src/misc/lua_cmake/src$ ls
CMakeLists.txt  lbaselib.c  ldo.c    lgc.h      lmathlib.c  lopcodes.c
 lstate.h   ltable.h   luac.c      lundump.h    Makefile
cscope.out      lcode.c     ldo.h    linit.c    lmem.c      lopcodes.h
 lstring.c  ltablib.c  luaconf.h   lvm.c
lapi.c          lcode.h     ldump.c  liolib.c   lmem.h      loslib.c
 lstring.h  ltm.c      lua.h       lvm.h
lapi.h          ldblib.c    lfunc.c  llex.c     loadlib.c   lparser.c
 lstrlib.c  ltm.h      lualib.h    lxmllib.cpp  print.c
lauxlib.c       ldebug.c    lfunc.h  llex.h     lobject.c   lparser.h
 lstruct.c  ltools.c   luatools.h  lzio.c
lauxlib.h       ldebug.h    lgc.c    llimits.h  lobject.h   lstate.c
 ltable.c   lua.c      lundump.c   lzio.h

The Makefile here is the original lua Makefile, I don't use it at all,
I use my CMakeLists.txt because I can cross-compile my lua on 5
different ARM or MIPS based platforms.

You'll noticed that I added some files into this directory, that is
ltools.c, luatools.h and lxmllib.cpp, okay, ltools is my own extension
module, and lxmllib.cpp is the LuaXML lib.

This is what I say to directly compile them with lua, just put the .c
and .cpp file into your lua directory and add them to your project (if
your project is Makefile then add in Makefile, if you had an IDE then
add file to project in your IDE).

You don't need the "require" statements at all if you compile modules
this way, you may need to call init function after luaL_openlibs() or
add the init functioninto linit.c.

I don't use luasocket, becasue socket support is already in my
ltools.c. and it sometimes is much easier to build your own module
than to fix the broken configure script.

In most case, add an external module to embedded lua is as simple as
add a new .c file into your project.