--- a/lua/CMakeLists.txt Mon Aug 04 19:33:53 2014 -0500
+++ b/lua/CMakeLists.txt Tue Aug 05 16:01:54 2014 -0500
@@ -20,7 +20,14 @@
- set(_LUAS "luajit>=2.0.0;lua5.2>=5.2.0;lua5.1>=5.1.0")
+ set(_LUAS "lua5.2>=5.2.0;lua5.1>=5.1.0;lua>=5.1") + # luajit doesn't work on 64bit osx, so only add it to the list if + set(_LUAS "${LUAS};luajit>=2.0") pkg_check_modules(LUA ${_LUA})
--- a/lua/gplugin-lua-test-lgi.c Mon Aug 04 19:33:53 2014 -0500
+++ b/lua/gplugin-lua-test-lgi.c Tue Aug 05 16:01:54 2014 -0500
@@ -16,18 +16,49 @@
+_add_require_path(lua_State *L, const char *path) { + const char *pkg_path = NULL; + lua_getglobal(L, "package"); + lua_getfield(L, -1, "path"); // get field "path" from table at top of stack (-1) + pkg_path = lua_tostring(L, -1); // grab path string from top of stack + memset(buff, 0, sizeof(buff)); + snprintf(buff, sizeof(buff), "%s;%s", pkg_path, path); + lua_pop(L, 1); // pop off the path field + lua_pushstring(L, buff); // push the new one + lua_setfield(L, -2, "path"); // set the field "path" in table at -2 with value at top of stack + lua_pop( L, 1 ); // get rid of package table from top of stack main(int argc, char *argv[]) {
- lua_State *L = luaL_newstate();
+ /* add some additional paths to package.path */ + _add_require_path(L, "/usr/local/lib/luarocks/rocks"); + luaL_dostring(L, "print(package.path)"); + /* now try to do the require */ lua_getglobal(L, "require");
lua_pushstring(L, "lgi");