From eb83bf8fd18946c4358f784fa39dad0731a6220a Mon Sep 17 00:00:00 2001 From: forever2k38 Date: Thu, 1 Oct 2026 15:44:53 +0200 Subject: feat: implement chdir function to remove dependency on lfs --- src/pow_lua.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/pow_lua.c b/src/pow_lua.c index 1d2f81a..0cd1019 100644 --- a/src/pow_lua.c +++ b/src/pow_lua.c @@ -228,7 +228,26 @@ int pow_lua_install(lua_State *L) { return 1; } -luaL_Reg libpow[] = {{"extract", pow_lua_extract}, {"install", pow_lua_install}, {NULL, NULL}}; +int pow_lua_chdir(lua_State *L) { + if (!lua_isstring(L, 1)) { + lua_pushnil(L); + lua_pushstring(L, "arg 1 must be string for chdir"); + + return 2; + } + + char *dir = lua_tostring(L, -1); + + int result = chdir(dir); + + if (result) { + pow_log_error("failed to chdir %d", result); + } + + return 1; +} + +luaL_Reg libpow[] = {{"chdir", pow_lua_chdir}, {"extract", pow_lua_extract}, {"install", pow_lua_install}, {NULL, NULL}}; int pow_lua_load(lua_State *L, pow_config *cfg) { luaL_newlib(L, libpow); -- cgit v1.3