add system.file_exist? (#19)

binding to the internal filesystem.exists, a less janky way of checking if a file exists in the path cache
This commit is contained in:
Riley Pierce 2023-08-01 08:28:08 +01:00 committed by GitHub
parent 7dd50c8546
commit 0a28d4cf3c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -133,6 +133,7 @@ RB_METHOD(mkxpSystemMemory);
RB_METHOD(mkxpReloadPathCache);
RB_METHOD(mkxpAddPath);
RB_METHOD(mkxpRemovePath);
RB_METHOD(mkxpFileExists);
RB_METHOD(mkxpLaunch);
RB_METHOD(mkxpGetJSONSetting);
@ -243,6 +244,7 @@ static void mriBindingInit() {
_rb_define_module_function(mod, "reload_cache", mkxpReloadPathCache);
_rb_define_module_function(mod, "mount", mkxpAddPath);
_rb_define_module_function(mod, "unmount", mkxpRemovePath);
_rb_define_module_function(mod, "file_exist?", mkxpFileExists);
_rb_define_module_function(mod, "launch", mkxpLaunch);
_rb_define_module_function(mod, "default_font_family=", mkxpSetDefaultFontFamily);
@ -574,6 +576,18 @@ RB_METHOD(mkxpRemovePath) {
return path;
}
RB_METHOD(mkxpFileExists) {
RB_UNUSED_PARAM;
VALUE path;
rb_scan_args(argc, argv, "1", &path);
SafeStringValue(path);
if (shState->fileSystem().exists(RSTRING_PTR(path)))
return Qtrue;
return Qfalse;
}
RB_METHOD(mkxpSetDefaultFontFamily) {
RB_UNUSED_PARAM;