mirror of
https://github.com/ctruLua/ctruLua.git
synced 2025-10-27 16:39:29 +00:00
Moved library path modifications to main.lua, made all paths relative
The library path can now be easlily modified. Instead of always launching /3ds/ctruLua/main.lua, ctruLua will now launch the main.lua in the current directory (the ctruLua.3dsx directory when launched with HBL). On citra, this will be the root of the sdmc directory.
This commit is contained in:
parent
81f8edb25d
commit
0efdc23576
6 changed files with 49 additions and 21 deletions
|
|
@ -167,17 +167,38 @@
|
|||
** hierarchy or if you want to install your libraries in
|
||||
** non-conventional directories.
|
||||
*/
|
||||
#define LUA_VDIR LUA_VERSION_MAJOR "." LUA_VERSION_MINOR "/"
|
||||
|
||||
#define LUA_ROOT "sdmc:/"
|
||||
#define LUA_LDIR LUA_ROOT "3ds/ctruLua/libs/"
|
||||
#define LUA_CDIR LUA_ROOT "3ds/ctruLua/libs/"
|
||||
#define LUA_VDIR LUA_VERSION_MAJOR "." LUA_VERSION_MINOR
|
||||
#if defined(_WIN32) /* { */
|
||||
/*
|
||||
** In Windows, any exclamation mark ('!') in the path is replaced by the
|
||||
** path of the directory of the executable file of the current process.
|
||||
*/
|
||||
#define LUA_LDIR "!\\lua\\"
|
||||
#define LUA_CDIR "!\\"
|
||||
#define LUA_SHRDIR "!\\..\\share\\lua\\" LUA_VDIR "\\"
|
||||
#define LUA_PATH_DEFAULT \
|
||||
LUA_LDIR"?.lua;" LUA_LDIR"?/init.lua;" \
|
||||
LUA_LDIR LUA_VDIR"?.lua;" LUA_LDIR LUA_VDIR"?/init.lua;" \
|
||||
LUA_LDIR"?.lua;" LUA_LDIR"?\\init.lua;" \
|
||||
LUA_CDIR"?.lua;" LUA_CDIR"?\\init.lua;" \
|
||||
LUA_SHRDIR"?.lua;" LUA_SHRDIR"?\\init.lua;" \
|
||||
".\\?.lua;" ".\\?\\init.lua"
|
||||
#define LUA_CPATH_DEFAULT \
|
||||
LUA_CDIR"?.dll;" \
|
||||
LUA_CDIR"..\\lib\\lua\\" LUA_VDIR "\\?.dll;" \
|
||||
LUA_CDIR"loadall.dll;" ".\\?.dll"
|
||||
|
||||
#else /* }{ */
|
||||
|
||||
#define LUA_ROOT "/usr/local/"
|
||||
#define LUA_LDIR LUA_ROOT "share/lua/" LUA_VDIR "/"
|
||||
#define LUA_CDIR LUA_ROOT "lib/lua/" LUA_VDIR "/"
|
||||
#define LUA_PATH_DEFAULT \
|
||||
LUA_LDIR"?.lua;" LUA_LDIR"?/init.lua;" \
|
||||
LUA_CDIR"?.lua;" LUA_CDIR"?/init.lua;" \
|
||||
"./?.lua;" "./?/init.lua"
|
||||
#define LUA_CPATH_DEFAULT \
|
||||
LUA_CDIR"?.so;" LUA_CDIR"loadall.so;" "./?.so"
|
||||
#endif /* } */
|
||||
|
||||
|
||||
/*
|
||||
@@ LUA_DIRSEP is the directory separator (for submodules).
|
||||
|
|
|
|||
|
|
@ -3,8 +3,8 @@ local hid = require("ctr.hid")
|
|||
local gfx = require("ctr.gfx")
|
||||
|
||||
-- Open libs
|
||||
local keyboard = dofile("sdmc:/3ds/ctruLua/keyboard.lua")
|
||||
local openfile = dofile("sdmc:/3ds/ctruLua/openfile.lua")
|
||||
local keyboard = require("keyboard")
|
||||
local openfile = require("openfile")
|
||||
local color = dofile("color.lua")
|
||||
local syntax = dofile("syntax.lua")
|
||||
|
||||
|
|
@ -12,7 +12,7 @@ local syntax = dofile("syntax.lua")
|
|||
local font = gfx.font.load("VeraMono.ttf")
|
||||
|
||||
-- Open file
|
||||
local path, status = openfile("Choose a file to edit", "/3ds/ctruLua/", nil, "any")
|
||||
local path, status = openfile("Choose a file to edit", nil, nil, "any")
|
||||
if not path then return end
|
||||
local lineEnding
|
||||
local lines = {}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,11 @@
|
|||
local fs = require("ctr.fs")
|
||||
|
||||
-- Set up path
|
||||
local ldir = fs.getDirectory().."libs/"
|
||||
package.path = package.path..";".. ldir.."?.lua;".. ldir.."?/init.lua"
|
||||
|
||||
repeat
|
||||
fs.setDirectory("sdmc:/3ds/ctruLua")
|
||||
local file = dofile("openfile.lua")("Choose a Lua file to execute", "/3ds/ctruLua/", ".lua", "exist")
|
||||
local file = require("openfile")("Choose a Lua file to execute", nil, ".lua", "exist")
|
||||
if file then
|
||||
fs.setDirectory(file:match("^(.-)[^/]*$"))
|
||||
dofile(file)
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
--- Open a file explorer to select a file.
|
||||
-- string title: title of the file explorer.
|
||||
-- string curdir: the directory to initially open the file explorer in.
|
||||
-- string curdir: the directory to initially open the file explorer in, or nil for the current directory.
|
||||
-- string exts: the file extensions the user can select, separated by ";". If nil, all extensions are accepted.
|
||||
-- string type: "exist" to select an existing file, "new" to select an non-existing file or "any" to select a existing
|
||||
-- or non-existing file name. If nil, defaults to "exist".
|
||||
|
|
@ -11,9 +11,10 @@ return function(title, curdir, exts, type)
|
|||
local ctr = require("ctr")
|
||||
local gfx = require("ctr.gfx")
|
||||
|
||||
local keyboard = dofile("sdmc:/3ds/ctruLua/keyboard.lua")
|
||||
local keyboard = require("keyboard")
|
||||
|
||||
-- Arguments
|
||||
local curdir = curdir or ctr.fs.getDirectory()
|
||||
local type = type or "exist"
|
||||
|
||||
-- Variables
|
||||
|
|
|
|||
13
source/fs.c
13
source/fs.c
|
|
@ -1,4 +1,6 @@
|
|||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <3ds/types.h>
|
||||
#include <3ds/util/utf.h>
|
||||
|
|
@ -88,12 +90,15 @@ static int fs_setDirectory(lua_State *L) {
|
|||
|
||||
int result = chdir(path);
|
||||
|
||||
if (result == 0)
|
||||
if (result == 0) {
|
||||
lua_pushboolean(L, true);
|
||||
else
|
||||
lua_pushboolean(L, false);
|
||||
return 1;
|
||||
|
||||
return 1;
|
||||
} else {
|
||||
lua_pushboolean(L, false);
|
||||
lua_pushstring(L, strerror(errno));
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
|
||||
static const struct luaL_Reg fs_lib[] = {
|
||||
|
|
|
|||
|
|
@ -4,8 +4,6 @@
|
|||
#include <lauxlib.h>
|
||||
#include <lualib.h>
|
||||
|
||||
#define BOOT_FILE "sdmc:/3ds/ctruLua/main.lua"
|
||||
|
||||
void load_ctr_lib(lua_State *L);
|
||||
void unload_ctr_lib(lua_State *L);
|
||||
|
||||
|
|
@ -47,7 +45,7 @@ int main() {
|
|||
load_ctr_lib(L);
|
||||
|
||||
// Do the actual thing
|
||||
if (luaL_dofile(L, BOOT_FILE)) error(luaL_checkstring(L, -1));
|
||||
if (luaL_dofile(L, "main.lua")) error(luaL_checkstring(L, -1));
|
||||
|
||||
// Unload libs
|
||||
unload_ctr_lib(L);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue