Skip to content

Commit

Permalink
Also add cpath in pdlua_packagepath.
Browse files Browse the repository at this point in the history
We don't need this right now, as pdx.lua is the only module in the pdlua
external directory that we load, which is Lua source only. However, we
might want to add other extensions that require a C module in the
future, or the user might want to put other Lua packages such as numlua
there for easy access.
  • Loading branch information
agraef committed Sep 12, 2024
1 parent c3fdad8 commit b08c85e
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions pdlua.c
Original file line number Diff line number Diff line change
Expand Up @@ -2289,6 +2289,23 @@ static void pdlua_packagepath(lua_State *L, const char *path)
lua_pushstring(L, "path");
lua_pushstring(L, buf);
lua_settable(L, -3);
lua_pushstring(L, "cpath");
lua_gettable(L, -2);
packagepath = lua_tostring(L, -1);
buf = realloc(buf, 2*strlen(path)+20+strlen(packagepath));
if (!buf) {
lua_pop(L, 2);
return;
}
#ifdef _WIN32
sprintf(buf, "%s\\?.dll;%s", path, packagepath);
#else
sprintf(buf, "%s/?.so;%s", path, packagepath);
#endif
lua_pop(L, 1);
lua_pushstring(L, "cpath");
lua_pushstring(L, buf);
lua_settable(L, -3);
lua_pop(L, 1);
free(buf);
PDLUA_DEBUG("pdlua_packagepath: end. stack top %d", lua_gettop(L));
Expand Down

0 comments on commit b08c85e

Please sign in to comment.