From b08c85e4df57a43dc4ff967707e6dd0e798a45b0 Mon Sep 17 00:00:00 2001 From: Albert Graef Date: Thu, 12 Sep 2024 12:19:32 +0200 Subject: [PATCH] Also add cpath in pdlua_packagepath. 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. --- pdlua.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/pdlua.c b/pdlua.c index f746ade..9ce1b98 100644 --- a/pdlua.c +++ b/pdlua.c @@ -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));