1 #include "lua/internal.hpp"
2 #include "interface/romtype.hpp"
3 #include "library/running-executable.hpp"
4 #include "library/string.hpp"
5 #include "core/misc.hpp"
6 #include "core/settings.hpp"
7 #include "core/moviedata.hpp"
8 #include "core/instance.hpp"
9 #include "core/project.hpp"
13 class value_unknown
{};
15 template<std::string(*value
)(lua::state
& L
, lua::parameters
& P
)>
16 int lua_push_string_fn(lua::state
& L
, lua::parameters
& P
)
19 L
.pushlstring(value(L
, P
));
20 } catch(value_unknown
) {
26 std::string
get_executable_file(lua::state
& L
, lua::parameters
& P
)
29 return running_executable();
31 throw value_unknown();
35 std::string
get_executable_path(lua::state
& L
, lua::parameters
& P
)
37 auto fname
= get_executable_file(L
, P
);
38 #if defined(__WIN32__) || defined(__WIN64__)
39 const char* pathsep
= "/\\";
41 const char* pathsep
= "/";
43 size_t split
= fname
.find_last_of(pathsep
);
44 if(split
>= fname
.length()) throw value_unknown();
45 return fname
.substr(0, split
);
48 std::string
l_get_config_path(lua::state
& L
, lua::parameters
& P
)
50 return get_config_path();
53 std::string
get_rompath(lua::state
& L
, lua::parameters
& P
)
55 return SET_rompath(*CORE().settings
);
58 std::string
get_firmwarepath(lua::state
& L
, lua::parameters
& P
)
60 return SET_firmwarepath(*CORE().settings
);
63 std::string
get_slotpath(lua::state
& L
, lua::parameters
& P
)
66 auto p
= core
.project
->get();
70 return SET_slotpath(*core
.settings
);
74 std::string
get_save_slot_file(lua::state
& L
, lua::parameters
& P
)
84 name
= (stringfmt() << "$SLOT:" << num
).str();
85 } else if(P
.is_string()) {
89 (stringfmt() << "Expected string or number as argument #1 to " << P
.get_fname()).throwex();
91 ret
= translate_name_mprefix(name
, binary_flag
, for_save
? 1 : -1);
95 lua::functions
LUA_paths_fns(lua_func_misc
, "paths", {
96 {"get_executable_file", lua_push_string_fn
<get_executable_file
>},
97 {"get_executable_path", lua_push_string_fn
<get_executable_path
>},
98 {"get_config_path", lua_push_string_fn
<l_get_config_path
>},
99 {"get_rompath", lua_push_string_fn
<get_rompath
>},
100 {"get_firmwarepath", lua_push_string_fn
<get_firmwarepath
>},
101 {"get_slotpath", lua_push_string_fn
<get_slotpath
>},
102 {"get_save_slot_file", lua_push_string_fn
<get_save_slot_file
>},