# HG changeset patch # User jbe # Date 1422498126 -3600 # Node ID 32e0838d16e679014898eb98831a54f7024b6f44 # Parent 4d7551c962d5d3255e123d976c5475881a618602 Added MOONBR_LUA_PATH compile-time variable to allow prepending a path to LUA_PATH at run-time diff -r 4d7551c962d5 -r 32e0838d16e6 Makefile --- a/Makefile Thu Jan 29 01:33:00 2015 +0100 +++ b/Makefile Thu Jan 29 03:22:06 2015 +0100 @@ -24,10 +24,14 @@ .endif +.ifdef MOONBR_LUA_PATH +MOONBR_LUA_PATH_DEFINE = "-DMOONBR_LUA_PATH=\"$(MOONBR_LUA_PATH)\"" +.endif + all:: moonbridge moonbridge: moonbridge.c - cc -Wall -O2 -Wl,-E -I $(LUA_INCLUDE) -L $(LUA_LIBDIR) -o moonbridge moonbridge.c -lm -l$(LUA_LIBRARY) $(UTIL_FLAGS) + cc -Wall -O2 -Wl,-E -I $(LUA_INCLUDE) -L $(LUA_LIBDIR) -o moonbridge $(MOONBR_LUA_PATH_DEFINE) moonbridge.c -lm -l$(LUA_LIBRARY) $(UTIL_FLAGS) clean:: rm -f moonbridge diff -r 4d7551c962d5 -r 32e0838d16e6 README --- a/README Thu Jan 29 01:33:00 2015 +0100 +++ b/README Thu Jan 29 03:22:06 2015 +0100 @@ -1,11 +1,24 @@ Quickstart guide: -$ make # hint: use bmake on GNU systems +$ make $ ./moonbridge example_application.lua +Hint: use bmake on GNU systems + Then connect to http://localhost:8080/ To learn more, check example_application.lua and reference.txt files. If you experence any touble during compilation, please edit the Makefile to match your system. + +Further notes: + +The moonbridge binary may be compiled with a string that gets prepended to +LUA_PATH in order to allow proper inclusion of "moonbridge_http.lua" +independent of the current working directory. Set the MOONBR_LUA_PATH variable +to a string consisting of the path where "moonbridge_http.lua" will be +installed plus "/?.lua" if you want to use this feature, e.g.: + +$ make MOONBR_LUA_PATH=/usr/local/lib/moonbridge/?.lua + diff -r 4d7551c962d5 -r 32e0838d16e6 moonbridge.c --- a/moonbridge.c Thu Jan 29 01:33:00 2015 +0100 +++ b/moonbridge.c Thu Jan 29 03:22:06 2015 +0100 @@ -2682,6 +2682,21 @@ } lua_atpanic(L, moonbr_lua_panic); luaL_openlibs(L); +#ifdef MOONBR_LUA_PATH + lua_getglobal(L, "package"); // on stack position 1 + lua_getfield(L, 1, "path"); // on stack position 2 + { + luaL_Buffer buf; + luaL_buffinit(L, &buf); + luaL_addstring(&buf, MOONBR_LUA_PATH); + luaL_addchar(&buf, ';'); + lua_pushvalue(L, 2); + luaL_addvalue(&buf); + luaL_pushresult(&buf); + } + lua_setfield(L, 1, "path"); + lua_settop(L, 0); +#endif if (luaL_newmetatable(L, LUA_FILEHANDLE)) { moonbr_log(LOG_CRIT, "Lua metatable LUA_FILEHANDLE does not exist"); moonbr_terminate_error();