mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
js: implement more functions for JS backend (#12167)
This commit is contained in:
@ -37,19 +37,36 @@ pub fn flush() {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn getpid() int {
|
||||
res := 0
|
||||
#res.val = $process.pid
|
||||
|
||||
return res
|
||||
}
|
||||
|
||||
// chmod change file access attributes of `path` to `mode`.
|
||||
// Octals like `0o600` can be used.
|
||||
pub fn chmod(path string, mode int) {
|
||||
pub fn chmod(path string, mode int) ? {
|
||||
$if js_node {
|
||||
#try {
|
||||
#$fs.chmodSync(''+path,mode.valueOf())
|
||||
#} catch (error) {
|
||||
#return error_with_code(new string("chmod failed: " + error.message),new int(error.code))
|
||||
#}
|
||||
} $else {
|
||||
return error('os.chmod() is available only for NodeJS')
|
||||
}
|
||||
}
|
||||
|
||||
// chown changes the owner and group attributes of `path` to `owner` and `group`.
|
||||
// Octals like `0o600` can be used.
|
||||
pub fn chown(path string, owner int, group int) {
|
||||
pub fn chown(path string, owner int, group int) ? {
|
||||
$if js_node {
|
||||
#try {
|
||||
#$fs.chownSync(''+path,owner.valueOf(),group.valueOf())
|
||||
#} catch (error) { return error_with_code(new string("chown failed: " + error.message),new int(error.code)) }
|
||||
} $else {
|
||||
return error('os.chown() is available only for NodeJS')
|
||||
}
|
||||
}
|
||||
|
||||
@ -89,7 +106,7 @@ pub fn execute(cmd string) Result {
|
||||
#let commands = cmd.str.split(' ');
|
||||
#let output = $child_process.spawnSync(commands[0],commands.slice(1,commands.length));
|
||||
#exit_code = new int(output.status)
|
||||
#stdout = newstring(output.stdout + '')
|
||||
#stdout = new string(output.stdout + '')
|
||||
|
||||
return Result{
|
||||
exit_code: exit_code
|
||||
@ -97,6 +114,14 @@ pub fn execute(cmd string) Result {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn system(cmd string) int {
|
||||
exit_code := 0
|
||||
#let commands = cmd.str.split(' ');
|
||||
#exit_code.val = $child_process.execSync(commands[0],commands.slice(1,commands.length));
|
||||
|
||||
return exit_code
|
||||
}
|
||||
|
||||
pub fn is_atty(fd int) int {
|
||||
res := 0
|
||||
#res.val = +tty.isatty(fd.val)
|
||||
|
Reference in New Issue
Block a user