1 When looking for lua shared objects, dynamically adjust the pathnames to
2 include "64/", when running a 64-bit lua executable.
7 /usr/lib/lua/5.2/64/gv.so
9 The lua maintainers are not interested in this patch.
11 --- src/loadlib.c.orig 2014-09-19 06:57:40.032464104 -0700
12 +++ src/loadlib.c 2014-09-19 16:39:01.502592411 -0700
18 +** Return 1 if template is a shared object (has an extension of ".so"),
22 +issharedobj(const char *template) {
24 + if (strlen(template) < 3)
26 + ext = template + strlen(template) - 3;
27 + return strcmp(ext, ".so") == 0;
31 +** Return 1 if this is a 64-bit executable, otherwise 0.
33 +static int is64bit() {
34 + return sizeof(void *) == 8;
37 static const char *searchpath (lua_State *L, const char *name,
41 luaL_Buffer msg; /* to build error message */
43 luaL_buffinit(L, &msg);
44 if (*sep != '\0') /* non-empty separator? */
45 name = luaL_gsub(L, name, sep, dirsep); /* replace it by 'dirsep' */
47 + name64 = calloc(strlen(name) + 4, 1);
48 + strcpy(name64, "64/");
49 + strcat(name64, name);
51 + name64 = strdup(name);
52 while ((path = pushnexttemplate(L, path)) != NULL) {
53 - const char *filename = luaL_gsub(L, lua_tostring(L, -1),
54 - LUA_PATH_MARK, name);
56 + const char *item = lua_tostring(L, -1);
58 + if (is64bit() && issharedobj(item)) {
60 + if (strstr(item, LUA_PATH_MARK))
61 + filename = (char *)luaL_gsub(L, item, LUA_PATH_MARK, name);
64 + * There's nothing to substitute, so we have to go digging through the
65 + * path to find where to put the 64-bit directory. Search for "/" in
66 + * the template element until we can't find any more, replace that with
67 + * "?", and replace that with "/64/".
70 + char *s = strdup(item);
71 + for (p1 = s; p1; p1 = strstr(p1 + 1, "/"))
77 + * We didn't find any slashes; that either means there aren't any, or
78 + * item is in the root directory.
81 + s = calloc(strlen(item) + 3, 1);
88 + filename = (char *)luaL_gsub(L, s, LUA_PATH_MARK, "/64/");
92 + filename = (char *)luaL_gsub(L, item, LUA_PATH_MARK, name);
93 lua_remove(L, -2); /* remove path template */
94 - if (readable(filename)) /* does file exist and is readable? */
95 + if (readable(filename)) { /* does file exist and is readable? */
97 return filename; /* return that file name */
99 lua_pushfstring(L, "\n\tno file " LUA_QS, filename);
100 lua_remove(L, -2); /* remove file name */
101 luaL_addvalue(&msg); /* concatenate error msg. entry */
103 luaL_pushresult(&msg); /* create error message */
105 return NULL; /* not found */
109 static int ll_searchpath (lua_State *L) {
110 const char *f = searchpath(L, luaL_checkstring(L, 1),
111 luaL_checkstring(L, 2),