File tree Expand file tree Collapse file tree 2 files changed +20
-1
lines changed
Expand file tree Collapse file tree 2 files changed +20
-1
lines changed Original file line number Diff line number Diff line change 44
55#include " engine/file.hpp"
66
7+ extern std::string base_path;
8+
79// wrap stdio funcs around blit:: funcs
810wrap_FILE *wrap_stdin = nullptr ;
911wrap_FILE *wrap_stdout = nullptr ;
@@ -44,8 +46,14 @@ wrap_FILE *wrap_fopen(const char *filename, const char *mode)
4446 blit_mode |= blit::OpenMode::read;
4547 }
4648
49+ std::string filename_str = filename;
50+
51+ // adjust relative filenames to root
52+ if (filename[0 ] == ' .' && filename[1 ] == ' /' )
53+ filename_str = base_path + (filename + 1 );
54+
4755 auto ret = new wrap_FILE;
48- ret->file .open (filename , blit_mode);
56+ ret->file .open (filename_str , blit_mode);
4957 ret->offset = 0 ;
5058
5159 ret->getc_buf_len = ret->getc_buf_off = 0 ;
Original file line number Diff line number Diff line change @@ -8,6 +8,8 @@ lua_State *L;
88bool has_update = true ;
99bool has_render = true ;
1010
11+ std::string base_path;
12+
1113void init () {
1214 set_screen_mode (ScreenMode::lores);
1315 screen.pen = Pen (0 , 0 , 0 , 255 );
@@ -20,9 +22,18 @@ void init() {
2022 lua_blit_update_state (L);
2123
2224 auto launchPath = blit::get_launch_path ();
25+
2326 if (!launchPath) {
2427 launchPath = " main.lua" ;
2528 }
29+
30+
31+ // set base path from dir of main script
32+ auto pos = std::string_view (launchPath).find_last_of (' /' );
33+ if (pos != std::string_view::npos)
34+ base_path = std::string_view (launchPath).substr (0 , pos);
35+
36+ // load the script
2637 auto err = luaL_loadfile (L, launchPath);
2738
2839 if (err) {
You can’t perform that action at this time.
0 commit comments