moonbridge

changeset 8:32e0838d16e6

Added MOONBR_LUA_PATH compile-time variable to allow prepending a path to LUA_PATH at run-time
author jbe
date Thu Jan 29 03:22:06 2015 +0100 (2015-01-29)
parents 4d7551c962d5
children 757902555204
files Makefile README moonbridge.c
line diff
     1.1 --- a/Makefile	Thu Jan 29 01:33:00 2015 +0100
     1.2 +++ b/Makefile	Thu Jan 29 03:22:06 2015 +0100
     1.3 @@ -24,10 +24,14 @@
     1.4  
     1.5  .endif
     1.6  
     1.7 +.ifdef MOONBR_LUA_PATH
     1.8 +MOONBR_LUA_PATH_DEFINE = "-DMOONBR_LUA_PATH=\"$(MOONBR_LUA_PATH)\""
     1.9 +.endif
    1.10 +
    1.11  all:: moonbridge
    1.12  
    1.13  moonbridge: moonbridge.c
    1.14 -	cc -Wall -O2 -Wl,-E -I $(LUA_INCLUDE) -L $(LUA_LIBDIR) -o moonbridge moonbridge.c -lm -l$(LUA_LIBRARY) $(UTIL_FLAGS)
    1.15 +	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)
    1.16  
    1.17  clean::
    1.18  	rm -f moonbridge
     2.1 --- a/README	Thu Jan 29 01:33:00 2015 +0100
     2.2 +++ b/README	Thu Jan 29 03:22:06 2015 +0100
     2.3 @@ -1,11 +1,24 @@
     2.4  Quickstart guide:
     2.5  
     2.6 -$ make  # hint: use bmake on GNU systems
     2.7 +$ make
     2.8  $ ./moonbridge example_application.lua
     2.9  
    2.10 +Hint: use bmake on GNU systems
    2.11 +
    2.12  Then connect to http://localhost:8080/
    2.13  
    2.14  To learn more, check example_application.lua and reference.txt files. If you
    2.15  experence any touble during compilation, please edit the Makefile to match
    2.16  your system.
    2.17  
    2.18 +
    2.19 +Further notes:
    2.20 +
    2.21 +The moonbridge binary may be compiled with a string that gets prepended to
    2.22 +LUA_PATH in order to allow proper inclusion of "moonbridge_http.lua"
    2.23 +independent of the current working directory. Set the MOONBR_LUA_PATH variable
    2.24 +to a string consisting of the path where "moonbridge_http.lua" will be
    2.25 +installed plus "/?.lua" if you want to use this feature, e.g.:
    2.26 +
    2.27 +$ make MOONBR_LUA_PATH=/usr/local/lib/moonbridge/?.lua
    2.28 +
     3.1 --- a/moonbridge.c	Thu Jan 29 01:33:00 2015 +0100
     3.2 +++ b/moonbridge.c	Thu Jan 29 03:22:06 2015 +0100
     3.3 @@ -2682,6 +2682,21 @@
     3.4      }
     3.5      lua_atpanic(L, moonbr_lua_panic);
     3.6      luaL_openlibs(L);
     3.7 +#ifdef MOONBR_LUA_PATH
     3.8 +    lua_getglobal(L, "package");  // on stack position 1
     3.9 +    lua_getfield(L, 1, "path");  // on stack position 2
    3.10 +    {
    3.11 +      luaL_Buffer buf;
    3.12 +      luaL_buffinit(L, &buf);
    3.13 +      luaL_addstring(&buf, MOONBR_LUA_PATH);
    3.14 +      luaL_addchar(&buf, ';');
    3.15 +      lua_pushvalue(L, 2);
    3.16 +      luaL_addvalue(&buf);
    3.17 +      luaL_pushresult(&buf);
    3.18 +    }
    3.19 +    lua_setfield(L, 1, "path");
    3.20 +    lua_settop(L, 0);
    3.21 +#endif
    3.22      if (luaL_newmetatable(L, LUA_FILEHANDLE)) {
    3.23        moonbr_log(LOG_CRIT, "Lua metatable LUA_FILEHANDLE does not exist");
    3.24        moonbr_terminate_error();

Impressum / About Us