From e5467b663d13126870598b7bd3bd2bb3648339e1 Mon Sep 17 00:00:00 2001 From: Firew0lf Date: Sat, 12 Mar 2016 23:14:42 +0100 Subject: [PATCH] Added ctr.root, close #7, changed the max path length to 1024 ctr.root is not exactly the path to ctruLua.3dsx minus the file name, but is equivalent with HBL and $ (other launchers may work too, and it works perfectly with Citra), and is "romfs:/" if romfs is enabl$ --- source/ctr.c | 16 ++++++++++++++++ source/fs.c | 6 +++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/source/ctr.c b/source/ctr.c index c7adad4..db919dc 100644 --- a/source/ctr.c +++ b/source/ctr.c @@ -3,6 +3,9 @@ The `ctr` module. @module ctr @usage local ctr = require("ctr") */ +#include +#include + #include <3ds/types.h> #include <3ds/services/apt.h> #include <3ds/os.h> @@ -202,6 +205,19 @@ int luaopen_ctr_lib(lua_State *L) { */ lua_pushstring(L, CTR_BUILD); lua_setfield(L, -2, "build"); + + /*** + Root directory of ctrµLua. Contains the working directory where ctrµLua has been launched OR the romfs root if romfs has been enabled. + @field root + */ + #ifdef ROMFS + char* buff = "romfs:"; + #else + char* buff = malloc(1024); + getcwd(buff, 1024); + #endif + lua_pushstring(L, buff); + lua_setfield(L, -2, "root"); return 1; } diff --git a/source/fs.c b/source/fs.c index 68e13e3..b3e2235 100644 --- a/source/fs.c +++ b/source/fs.c @@ -40,7 +40,7 @@ const char* prefix_path(const char* path) { char* prefix = "sdmc:"; #endif - char out[256]; + char out[1024]; strcpy(out, prefix); return strcat(out, path); @@ -156,9 +156,9 @@ Get the current working directory. @treturn string the current working directory */ static int fs_getDirectory(lua_State *L) { - char cwd[256]; + char cwd[1024]; - lua_pushstring(L, getcwd(cwd, 256)); + lua_pushstring(L, getcwd(cwd, 1024)); return 1; }