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.3/64/gv.so
9 The lua maintainers are not interested in this patch.
11 --- lua-5.3.2/src/loadlib.c.~1~ 2017-03-10 20:14:16.979286128 +0300
12 +++ lua-5.3.2/src/loadlib.c 2017-03-10 20:20:03.100208291 +0300
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);
94 lua_remove(L, -2); /* remove path template */
95 - if (readable(filename)) /* does file exist and is readable? */
96 + if (readable(filename)) { /* does file exist and is readable? */
98 return filename; /* return that file name */
100 lua_pushfstring(L, "\n\tno file '%s'", filename);
101 lua_remove(L, -2); /* remove file name */
102 luaL_addvalue(&msg); /* concatenate error msg. entry */
104 luaL_pushresult(&msg); /* create error message */
106 return NULL; /* not found */