moonbridge
diff moonbridge.c @ 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 | 0449f6a4005f |
| children | 757902555204 |
line diff
1.1 --- a/moonbridge.c Thu Jan 29 01:33:00 2015 +0100 1.2 +++ b/moonbridge.c Thu Jan 29 03:22:06 2015 +0100 1.3 @@ -2682,6 +2682,21 @@ 1.4 } 1.5 lua_atpanic(L, moonbr_lua_panic); 1.6 luaL_openlibs(L); 1.7 +#ifdef MOONBR_LUA_PATH 1.8 + lua_getglobal(L, "package"); // on stack position 1 1.9 + lua_getfield(L, 1, "path"); // on stack position 2 1.10 + { 1.11 + luaL_Buffer buf; 1.12 + luaL_buffinit(L, &buf); 1.13 + luaL_addstring(&buf, MOONBR_LUA_PATH); 1.14 + luaL_addchar(&buf, ';'); 1.15 + lua_pushvalue(L, 2); 1.16 + luaL_addvalue(&buf); 1.17 + luaL_pushresult(&buf); 1.18 + } 1.19 + lua_setfield(L, 1, "path"); 1.20 + lua_settop(L, 0); 1.21 +#endif 1.22 if (luaL_newmetatable(L, LUA_FILEHANDLE)) { 1.23 moonbr_log(LOG_CRIT, "Lua metatable LUA_FILEHANDLE does not exist"); 1.24 moonbr_terminate_error();