diff --git a/src/vm.c b/src/vm.c index 76b4fd1..261d05a 100644 --- a/src/vm.c +++ b/src/vm.c @@ -559,7 +559,13 @@ static void system_call(enum syscall_code code) case SYS_EXISTS_FILE: { // system.ExistsFile(string szFileName) int str = stack_pop().i; char *path = gamedir_path(heap_get_string(str)->text); - stack_push(file_exists(path)); + int len = strlen(path); + // Return true for directories, but false if the path ends with a directory separator. + if (len > 0 && (path[len-1] == '/' || path[len-1] == '\\')) { + stack_push(0); + } else { + stack_push(file_exists(path)); + } heap_unref(str); free(path); break; diff --git a/test/Run/test.ain b/test/Run/test.ain index 93f2e6a..a019880 100644 Binary files a/test/Run/test.ain and b/test/Run/test.ain differ diff --git a/test/Source/main.jaf b/test/Source/main.jaf index 411d234..965218e 100755 --- a/test/Source/main.jaf +++ b/test/Source/main.jaf @@ -84,6 +84,10 @@ int main(void) test_arrays(); test_end("arrays"); + test_start("system"); + test_system(); + test_end("system"); + test_start("Math.dll"); test_math(); test_end("Math.dll"); diff --git a/test/Source/system.jaf b/test/Source/system.jaf new file mode 100644 index 0000000..6fe3876 --- /dev/null +++ b/test/Source/system.jaf @@ -0,0 +1,8 @@ +// -*-mode: C; coding: sjis; -*- + +void test_system(void) +{ + string savedir = system.GetSaveFolderName(); + test_equal("system.ExistFile(savedir) == 1", system.ExistFile(savedir), 1); + test_equal("system.ExistFile(savedir + \"\\\\\") == 1", system.ExistFile(savedir + "\\"), 0); +} diff --git a/test/Source/test.inc b/test/Source/test.inc index 5ae260a..258b5a0 100755 --- a/test/Source/test.inc +++ b/test/Source/test.inc @@ -4,6 +4,7 @@ Source = { "arithmetic.jaf", "strings.jaf", "structs.jaf", +"system.jaf", "arrays.jaf", "math.jaf" }