Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
See what's new at GitLab
4
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Switch to GitLab Next
Sign in / Register
Toggle navigation
Dukboot
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
1
Issues
1
List
Boards
Labels
Service Desk
Milestones
Iterations
Merge Requests
0
Merge Requests
0
Requirements
Requirements
List
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Operations
Operations
Incidents
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
Code Review
Insights
Issue
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
dukboot
Dukboot
Commits
fd80f4f4
Unverified
Commit
fd80f4f4
authored
May 15, 2017
by
Will Hilton
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add a 'dir' function
parent
a9e26b95
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
36 additions
and
3 deletions
+36
-3
example.js
example.js
+3
-3
src/app_push_dir.c
src/app_push_dir.c
+26
-0
src/main.c
src/main.c
+7
-0
No files found.
example.js
View file @
fd80f4f4
function
(
args
)
{
var
env
=
args
.
environ
;
var
argv
=
args
.
argv
return
argv
var
result
=
Object
.
keys
(
env
);
var
argv
=
args
.
argv
;
var
modules
=
args
.
modules
;
var
result
=
modules
.
dir
(
'
./src
'
);
print
(
JSON
.
stringify
(
result
));
return
result
}
src/app_push_dir.c
0 → 100644
View file @
fd80f4f4
#include <dirent.h>
#include <stdio.h>
int
app_push_dir
(
duk_context
*
ctx
)
{
// Check argument
const
char
*
dirname
=
duk_require_string
(
ctx
,
-
1
);
// Construct array
duk_idx_t
dir_idx
=
duk_push_array
(
ctx
);
// Shove filenames into array
struct
dirent
*
dir
;
int
i
=
0
;
DIR
*
d
=
opendir
(
dirname
);
if
(
d
)
{
while
(
i
<
100
)
{
dir
=
readdir
(
d
);
if
(
dir
==
NULL
)
break
;
duk_push_string
(
ctx
,
dir
->
d_name
);
duk_put_prop_index
(
ctx
,
dir_idx
,
i
);
i
++
;
}
closedir
(
d
);
}
return
1
;
}
src/main.c
View file @
fd80f4f4
...
...
@@ -13,6 +13,7 @@
#include "app_push_argv.c"
#include "app_push_environ.c"
#include "app_push_dir.c"
#include "native_print.c"
#include "native_adder.c"
#include "native_import.c"
...
...
@@ -53,7 +54,13 @@ int main(int argc, char *argv[] /* char *environ[] */) {
// Create environment variables object
ret
=
app_push_environ
(
ctx
);
duk_put_prop_string
(
ctx
,
argument_idx
,
"environ"
);
// Provide access to native functions
ret
=
duk_push_object
(
ctx
);
duk_push_c_function
(
ctx
,
app_push_dir
,
1
);
duk_put_prop_string
(
ctx
,
ret
,
"dir"
);
duk_put_prop_string
(
ctx
,
argument_idx
,
"modules"
);
// Run top-level module
ret
=
duk_pcall
(
ctx
,
1
);
if
(
ret
!=
0
)
{
fprintf
(
stderr
,
"%s %s
\n
"
,
argv
[
1
],
duk_safe_to_string
(
ctx
,
-
1
));
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment