lua-users home
lua-l archive

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



On 1-Dec-05, at 1:24 PM, Keith Wiles wrote:

I guess what I am asking for is for Lua to provide these hooks in the standard package and any other areas within Lua a developer may want to effect change (to a given point of course). I guess I could be making a big thing over nothing, but it does seem reasonable to me as it would be fairly simple to polish these areas for a cleaner package.

Well, I guess in that case, Luiz's answer was pretty good. linit.c *is* the hook, and it's a pretty good one. All you have to do is create one with the appropriate list in the definition of lualibs; something which could easily be done with a script if you were that way inclined. Since you might not want all of the standard libraries in a given embedded build -- particularly such things as io, os, debug, and loadlib --, customization is likely to be more than just adding to the list, anyway.

You can then build your own CLI in a project in a pretty straightforward manner. I'm no Makefile guru but something like this ought to work: (pretty well untested, I admit)

AWK= /usr/bin/awk
LUA= /usr/local/src/lua-5.1-beta
OBJS= mylinit.o joystick.o extra.o
LUALIBS= math string table package joystick extra

all: mylua

mylinit.c: Makefile
        echo '#include <lua.h>' > mylinit.h
for L in $(LUALIBS); do echo "int luaopen_$$L (lua_State *L);" >> mylinit.h; done
        echo '#include "mylinit.h"' > mylinit.c
        $(AWK) 'NR==1, /luaopen_base/' $(LUA)/src/linit.c >> mylinit.c
for L in $(LUALIBS); do echo " {\"$$L\", luaopen_$$L }," >> mylinit.c; done
        $(AWK) '/NULL, NULL/, true' $(LUA)/src/linit.c >> mylinit.c

mylinit.o: mylinit.c
        $(CC) -I $(LUA)/src -c -o $@ $?

libmystuff.a: $(OBJS)
        $(AR) $@ $?
        $(RANLIB) $@

mylua: libmystuff.a
$(CC) -I $(LUA)/src -L . -L $(LUA)/src $(LUA)/src/lua.o -lmystuff -llua