gplugin/gplugin

a bunch more work... not worth getting into the details yet
feature/osx-fixing
2014-08-05, Gary Kramlich
3873430754ef
Parents f1d274fe74d1
Children 0275b6a0e1c3
a bunch more work... not worth getting into the details yet
--- 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 @@
gplugin-lua-plugin.h
)
- 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
+ # we're not on mac
+ if(NOT APPLE)
+ set(_LUAS "${LUAS};luajit>=2.0")
+ endif(NOT APPLE)
+
foreach(_LUA ${_LUAS})
if(NOT LUA_FOUND)
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 @@
*/
#include <stdio.h>
+#include <string.h>
#include <lua.h>
#include <lauxlib.h>
#include <lualib.h>
+static void
+_add_require_path(lua_State *L, const char *path) {
+ const char *pkg_path = NULL;
+ char buff[255];
+
+ 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
+}
+
int
main(int argc, char *argv[]) {
- lua_State *L = luaL_newstate();
+ lua_State *L = NULL;
int ret = 0;
+ L = luaL_newstate();
+ if(L == NULL) {
+ printf("fml\n");
+ return 134;
+ }
+
luaL_openlibs(L);
+ /* 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");