mirror of https://github.com/bjornbytes/lovr.git
Add lovr.filesystem.getWorkingDirectory;
This commit is contained in:
parent
fdb3a29a05
commit
4b82a12b15
|
@ -94,7 +94,7 @@ int l_lovrFilesystemCreateDirectory(lua_State* L) {
|
|||
}
|
||||
|
||||
int l_lovrFilesystemGetAppdataDirectory(lua_State* L) {
|
||||
char buffer[1024];
|
||||
char buffer[LOVR_PATH_MAX];
|
||||
|
||||
if (lovrFilesystemGetAppdataDirectory(buffer, sizeof(buffer))) {
|
||||
lua_pushnil(L);
|
||||
|
@ -113,7 +113,7 @@ int l_lovrFilesystemGetDirectoryItems(lua_State* L) {
|
|||
}
|
||||
|
||||
int l_lovrFilesystemGetExecutablePath(lua_State* L) {
|
||||
char buffer[1024];
|
||||
char buffer[LOVR_PATH_MAX];
|
||||
|
||||
if (lovrFilesystemGetExecutablePath(buffer, sizeof(buffer))) {
|
||||
lua_pushnil(L);
|
||||
|
@ -197,6 +197,18 @@ int l_lovrFilesystemGetUserDirectory(lua_State* L) {
|
|||
return 1;
|
||||
}
|
||||
|
||||
int l_lovrFilesystemGetWorkingDirectory(lua_State* L) {
|
||||
char buffer[LOVR_PATH_MAX];
|
||||
|
||||
if (lovrFilesystemGetWorkingDirectory(buffer, sizeof(buffer))) {
|
||||
lua_pushnil(L);
|
||||
} else {
|
||||
lua_pushstring(L, buffer);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int l_lovrFilesystemIsDirectory(lua_State* L) {
|
||||
const char* path = luaL_checkstring(L, 1);
|
||||
lua_pushboolean(L, lovrFilesystemIsDirectory(path));
|
||||
|
@ -316,6 +328,7 @@ const luaL_Reg lovrFilesystem[] = {
|
|||
{ "getSize", l_lovrFilesystemGetSize },
|
||||
{ "getSource", l_lovrFilesystemGetSource },
|
||||
{ "getUserDirectory", l_lovrFilesystemGetUserDirectory },
|
||||
{ "getWorkingDirectory", l_lovrFilesystemGetWorkingDirectory },
|
||||
{ "isDirectory", l_lovrFilesystemIsDirectory },
|
||||
{ "isFile", l_lovrFilesystemIsFile },
|
||||
{ "isFused", l_lovrFilesystemIsFused },
|
||||
|
|
|
@ -121,8 +121,8 @@ int lovrFilesystemGetExecutablePath(char* dest, unsigned int size) {
|
|||
return 1;
|
||||
#elif __linux__
|
||||
memset(dest, 0, size);
|
||||
if (readlink("/proc/self/exe", dest, size) == -1) {
|
||||
return 1;
|
||||
if (readlink("/proc/self/exe", dest, size) != -1) {
|
||||
return 0;
|
||||
}
|
||||
#else
|
||||
#error "This platform is missing an implementation for lovrFilesystemGetExecutablePath"
|
||||
|
@ -177,6 +177,20 @@ const char* lovrFilesystemGetUserDirectory() {
|
|||
#endif
|
||||
}
|
||||
|
||||
int lovrFilesystemGetWorkingDirectory(char* dest, unsigned int size) {
|
||||
#ifdef _WIN32
|
||||
WCHAR w_cwd[LOVR_PATH_MAX];
|
||||
_wgetcwd(w_cwd, LOVR_PATH_MAX);
|
||||
PHYSFS_utf8FromUtf16(w_cwd, dest, size);
|
||||
return 0;
|
||||
#else
|
||||
if (getcwd(dest, size)) {
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
return 1;
|
||||
}
|
||||
|
||||
bool lovrFilesystemIsDirectory(const char* path) {
|
||||
PHYSFS_Stat stat;
|
||||
return PHYSFS_stat(path, &stat) ? stat.filetype == PHYSFS_FILETYPE_DIRECTORY : false;
|
||||
|
|
|
@ -34,6 +34,7 @@ const char* lovrFilesystemGetSaveDirectory();
|
|||
size_t lovrFilesystemGetSize(const char* path);
|
||||
const char* lovrFilesystemGetSource();
|
||||
const char* lovrFilesystemGetUserDirectory();
|
||||
int lovrFilesystemGetWorkingDirectory(char* dest, unsigned int size);
|
||||
bool lovrFilesystemIsDirectory(const char* path);
|
||||
bool lovrFilesystemIsFile(const char* path);
|
||||
bool lovrFilesystemIsFused();
|
||||
|
|
Loading…
Reference in New Issue