• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

ArkScript-lang / Ark / 14640812317

24 Apr 2025 11:46AM UTC coverage: 83.196% (+2.8%) from 80.417%
14640812317

Pull #530

github

web-flow
Merge 718abfdf5 into 32828a045
Pull Request #530: Feat/inst locations

290 of 380 new or added lines in 20 files covered. (76.32%)

7 existing lines in 3 files now uncovered.

6560 of 7885 relevant lines covered (83.2%)

79291.33 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

17.5
/src/arkreactor/Builtins/System.cpp
1
#include <Ark/Builtins/Builtins.hpp>
2

3
#include <stdio.h>
4
#include <memory>
5
#include <cstdlib>
6
#include <thread>
7

8
#ifdef _MSC_VER
9
#    define popen _popen
10
#    define pclose _pclose
11
#endif
12

13
#undef abs
14
#include <chrono>
15

16
#include <Ark/Constants.hpp>
17
#include <Ark/TypeChecker.hpp>
18
#include <Ark/VM/VM.hpp>
19

20
namespace Ark::internal::Builtins::System
21
{
22
    namespace
23
    {
24
        struct close_file_deleter
25
        {
26
            int operator()(FILE* file) const noexcept
×
27
            {
×
28
                return pclose(file);
×
29
            }
30
        };
31
    }
32

33
    /**
34
     * @name sys:exec
35
     * @brief Execute a system specific command
36
     * @details Return the output of the command as a String, or nil if it was disabled in the ArkScript build
37
     * @param command the command to execute, as a String
38
     * =begin
39
     * (sys:exec "echo hello")
40
     * =end
41
     * @author https://github.com/SuperFola
42
     */
43
    Value system_(std::vector<Value>& n, VM* vm [[maybe_unused]])
×
44
    {
×
45
        if (!types::check(n, ValueType::String))
×
NEW
46
            throw types::TypeCheckingError(
×
47
                "sys:exec",
×
48
                { { types::Contract { { types::Typedef("command", ValueType::String) } } } },
×
49
                n);
×
50

51
#ifdef ARK_ENABLE_SYSTEM
52
        std::array<char, 128> buffer;
×
53
        std::string result;
×
54
        std::unique_ptr<FILE, close_file_deleter> pipe(popen(n[0].string().c_str(), "r"), close_file_deleter());
×
55
        if (!pipe)
×
56
            throw std::runtime_error("sys:exec: couldn't retrieve command output");
×
57
        while (fgets(buffer.data(), buffer.size(), pipe.get()) != nullptr)
×
58
            result += buffer.data();
×
59
        return Value(result);
×
60
#else
61
        return nil;
62
#endif  // ARK_ENABLE_SYSTEM
63
    }
×
64

65
    /**
66
     * @name sys:sleep
67
     * @brief Sleep for a given duration (in milliseconds)
68
     * @details Return nil
69
     * @param duration a Number representing a duration
70
     * =begin
71
     * (sys:sleep 1000)  # sleep for 1 second
72
     * =end
73
     * @author https://github.com/SuperFola
74
     */
75
    Value sleep(std::vector<Value>& n, VM* vm [[maybe_unused]])
2✔
76
    {
2✔
77
        if (!types::check(n, ValueType::Number))
2✔
NEW
78
            throw types::TypeCheckingError(
×
79
                "sys:sleep",
×
80
                { { types::Contract { { types::Typedef("duration", ValueType::Number) } } } },
×
81
                n);
×
82

83
        auto duration = std::chrono::duration<double, std::ratio<1, 1000>>(n[0].number());
2✔
84
        std::this_thread::sleep_for(duration);
2✔
85

86
        return nil;
2✔
87
    }
2✔
88

89
    /**
90
     * @name sys:exit
91
     * @brief Reverse a given list and return a new one
92
     * @details Any code after this function call won't be executed
93
     * @param exitCode usually 0 for success and 1 for errors
94
     * =begin
95
     * (sys:exit 0)  # halt the virtual machine with given exit code (success)
96
     * =end
97
     * @author https://github.com/SuperFola
98
     */
99
    Value exit_(std::vector<Value>& n, VM* vm)
×
100
    {
×
101
        if (!types::check(n, ValueType::Number))
×
NEW
102
            throw types::TypeCheckingError(
×
103
                "sys:exit",
×
104
                { { types::Contract { { types::Typedef("exitCode", ValueType::Number) } } } },
×
105
                n);
×
106

107
        vm->exit(static_cast<int>(n[0].number()));
×
108
        return nil;
×
109
    }
×
110
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc