[Debugger] JS API: add fs.exists (#2158)

This commit is contained in:
shyguyhex 2021-12-31 21:56:03 -06:00 committed by GitHub
parent 9b5f45ea23
commit 219b9149d6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 3 deletions

View File

@ -1,8 +1,8 @@
<!DOCTYPE html>
<!-- Generated Sep 28 2021 -->
<!-- Generated Dec 31 2021 -->
<!-- YAML source: https://github.com/shygoo/pj64d-docs -->
<head>
<title>Project64 JavaScript API 2021.09.28</title>
<title>Project64 JavaScript API 2021.12.31</title>
<link href='https://fonts.googleapis.com/css?family=Open+Sans:400,400italic,700,700italic' rel='stylesheet' type='text/css'>
<style>
:root {
@ -279,7 +279,7 @@ window.addEventListener('load', function() {
<div class="sidebar">
<div class="sidebar-content">
<div class="pagetitle">Project64 JavaScript API</div>
2021.09.28
2021.12.31
<hr>
<ul>
<p><li><a class="" href="#Project64 JavaScript API">Project64 JavaScript API</a><ul>
@ -393,6 +393,7 @@ window.addEventListener('load', function() {
<li><a class="" href="#fs_writefile">fs.writefile(path, buffer)</a></li>
<li><a class="" href="#fs_read">fs.read(fd, buffer, offset, length, position)</a></li>
<li><a class="" href="#fs_readfile">fs.readfile(path)</a></li>
<li><a class="" href="#fs_exists">fs.exists(path)</a></li>
<li><a class="" href="#fs_fstat">fs.fstat(fd)</a></li>
<li><a class="" href="#fs_stat">fs.stat(path)</a></li>
<li><a class="" href="#fs_unlink">fs.unlink(path)</a></li>
@ -1460,6 +1461,11 @@ Reads data from the file referenced by <span class="snip">fd</span> into <span c
<div class="tsproto">fs.readfile(path: string): Buffer</div>
</p>
Returns a <a target="blank" href="https://nodejs.org/docs/v6.9.1/api/buffer.html">Buffer</a> object representing the data of the file specified by <span class="snip">path</span>.
<!-- fs_exists -->
<p><div class="prop"><span class="title" id="fs_exists">fs.exists(path)</span></div>
<div class="tsproto">fs.exists(path: string): boolean</div>
</p>
Returns <span class="snip">true</span> if the path exists.
<!-- fs_fstat -->
<p><div class="prop"><span class="title" id="fs_fstat">fs.fstat(fd)</span></div>
<div class="tsproto">fs.fstat(fd: number): fs.Stats</div>

View File

@ -203,6 +203,7 @@ namespace ScriptAPI
duk_ret_t js_fs_writefile(duk_context* ctx);
duk_ret_t js_fs_read(duk_context* ctx);
duk_ret_t js_fs_readfile(duk_context* ctx);
duk_ret_t js_fs_exists(duk_context* ctx);
duk_ret_t js_fs_fstat(duk_context* ctx);
duk_ret_t js_fs_stat(duk_context* ctx);
duk_ret_t js_fs_unlink(duk_context* ctx);

View File

@ -19,6 +19,7 @@ void ScriptAPI::Define_fs(duk_context *ctx)
{ "writefile", js_fs_writefile, DUK_VARARGS },
{ "read", js_fs_read, DUK_VARARGS },
{ "readfile", js_fs_readfile, DUK_VARARGS },
{ "exists", js_fs_exists, DUK_VARARGS },
{ "fstat", js_fs_fstat, DUK_VARARGS },
{ "stat", js_fs_stat, DUK_VARARGS },
{ "unlink", js_fs_unlink, DUK_VARARGS },
@ -234,6 +235,14 @@ duk_ret_t ScriptAPI::js_fs_readfile(duk_context *ctx)
return 1;
}
duk_ret_t ScriptAPI::js_fs_exists(duk_context* ctx)
{
CheckArgs(ctx, { Arg_String });
const char* path = duk_get_string(ctx, 0);
duk_push_boolean(ctx, PathFileExistsA(path) ? 1 : 0);
return 1;
}
duk_ret_t ScriptAPI::js_fs_fstat(duk_context *ctx)
{
CheckArgs(ctx, { Arg_Number });